kony.shareExtensions Namespace
The kony.shareExtensions Namespace implements the iOS Share extension, which is a type of app extension.
The Share app extension is one of the types of app extensions provided by Apple for iOS apps. The Share app extension allows the app users to share information from the current context with other entities, such as social media, apps, and services. For example, a Share app extension can be used to share photos directly from the Image Gallery with the social media.
The share extension app can be accessed by tapping an action button provided in an app to display the activity view. The activity view contains extensions relevant to the current context.
Quantum Visualizerprovides integrated support for developing Share app extensions for iOS apps. You develop Share extensions and package them into your app in the same way you do for other types of app extensions. For more information, refer App Extension API for iOS.
For more information about what the Share app extension is and what you can do with it, refer the Apple developer documentation.
A Share extension can use the default UI provided by Apple or a custom UI that you create. When you create a share extension using the Default GUI, a standard compose view UI is used as shown in the figure below.
The implementation of the kony.shareExtensions Namespace provides you with what you need to add your own business logic using the Native Function API in callback handlers.
If you create your own custom UI, you must use the Native Function API and then add your business logic according to your needs. The Info.plist file generated when you create a Share app extension from Xcode is configured to use the Default UI by default. To make use of the custom UI for your app extension, you need to perform the following steps.
- Open the Info.plist file of the Share app extension for which you want to develop a custom UI.
-
Find and replace the
NSExtensionMainStoryboard
key withNSExtensionPrincipalClass
, and also replace its value,MainInterface
withShareViewController
. The figure below shows difference in the Info.plist file before and after modification. - Save and close the file.
When you develop a Share extension, you put your business logic into a specific set of callback functions. Your app must set these callback function by invoking the kony.shareExtensions.setExtensionsCallbacks function.
Properties
The kony.shareExtensions Namespace provides the following properties.
Sets an initial value to be displayed as the number of characters remaining in the placeholder.
Syntax
kony.shareExtensions.charactersRemaining;
Example
//Sample code
kony.shareExtensions.charactersRemaining = 100;
Type
Number
Read/Write
Read and write.
Remarks
This property is accessible only in the default GUI mode.
Platform Availability
iOS
Contains the text from the current textView.
Syntax
kony.shareExtensions.contentText;
Example
//Sample code
var text = kony.shareExtensions.contentText;
Type
String
Return Values
text
Remarks
This property is only available in the default GUI mode.
Platform Availability
iOS
Returns the current extension context.
Syntax
kony.shareExtensions.extensionContext;
Example
//Sample code
var Context = kony.shareExtensions.extensionContext; Context.extensionContext.completeRequestReturningItemsCompletionHandler([], );
Type
Object
Read/Write
Read only
Platform Availability
iOS
Sets the text for the share app extension in the placeholder.
Syntax
kony.shareExtensions.placeholder;
Example
//Sample code
kony.shareExtensions.placeholder = "write here";
Type
String
Read/Write
Read and write.
Remarks
The API works only in default GUI mode.
Platform Availability
iOS
Holds the current extension view.
Syntax
kony.shareExtensions.view;
Example
//Sample code
var myView = kony.shareExtensions.view; myView.addSubView(button);
Type
UIView
Read/Write
Read only.
Platform Availability
iOS
Functions
The kony.shareExtensions Namespace provides the following function.
Dismisses the current configuration view controller.
Syntax
kony.shareExtensions.popConfigurationViewController()
Example
//Sample code
kony.shareExtensions.popConfigurationViewController();
Parameters
None.
Return Values
None.
Remarks
The function works only in the default GUI mode.
Platform Availability
iOS.
Displays a configuration view controller.
Syntax
kony.shareExtensions.pushConfigurationViewController(UIVController)
Input Parameters
Parameter | Description |
---|---|
UIViewController | A UIViewController that your app creates using the Native Functions. |
Example
var UIVC = //native bindings code to create UIViewController
kony.shareExtensions.pushConfigurationViewController(UIVC);
Return Values
None.
Remarks
The function works only in the default GUI mode. The configuration view controller is called from a configuration item's tabHandler. Only one configuration view controller is allowed at a time. The pushed view controller should set preferredContentSize
appropriately. The SLComposeServiceViewController
observes changes to that property and animates sheet size changes as necessary.
Platform Availability
iOS.
Allows your app to set callback event handlers for a Share extension.
Syntax
kony.shareExtensions.setExtensionsCallbacks(callbacks);
Input Parameters
callbacks {Object}
Contains an object with key-value pairs where the key specifies the extension state and the value is a callback function. The following are the possible keys.
Key | Description |
---|---|
configurationItems | Enables the user to add configuration options via table cells at the bottom of the sheet, Returns an array of SLComposeSheetConfigurationItem objects. Only available in default GUI mode. |
didSelectCancel | The user clicked the Cancel button. Only available in default GUI mode. |
didSelectPost | The user clicked the Post button. Only available in default GUI mode. |
isContentValid | Determines whether or not the content is valid. Only available in default GUI mode. Invalid content disables the Post button. Valid content enables it. |
loadView | Loads the view into memory. |
presentationAnimationDidFinish | The sheet presentation animation is finished. Only available in default GUI mode. |
viewDidAppear | The view was just displayed. |
viewWillAppear | The view controller's view is about to be added to a view hierarchy. |
viewDidDisappear | The view has just been removed from the view hierarchy. |
viewWillDisappear | The view is about to be removed from the view hierarchy. |
Example
var callbackEvents = { didSelectCancel: function() { kony.shareExtensions.extensionContext.cancelRequestWithError(undefined); }, isContentValid: function() { var input = kony.shareExtensions.contentText; if (input.length < 100) { kony.shareExtensions.charactersRemaining = 100 - input.length; return true; } else { return false; } }, configurationItems: function() { return [ConfigurationItem1, ConfigurationItem2]; }, viewDidLoad: function() { kony.shareExtensions.charactersRemaining = 100; } }; kony.shareExtensions.setExtensionsCallbacks(callbackEvents);
Example: configurationItems
function configurationItems() { var returnarray = native bindings code to return array of SLComposeSheetConfigurationItem return returnarray; } kony.shareExtensions.setExtensionsCallbacks({“ configurationItems”: configurationItems });
Example: didSelectCancel
function didSelectCancelcallback() { // native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ didSelectCancel”: didSelectCancelcallback });
Example: didSelectPostcallback
function didSelectPostcallback() { // native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ didSelectPost”: didSelectPostcallback });
Example: isContentValid
function isContentValid() { if ( //check the validity of the input using native bindings code) { return true; //will enable the post button. } return false; //will disable the post button. } kony.shareExtensions.setExtensionsCallbacks({“ isContentValid”: isContentValid });
Example; loadView
function loadView() { //native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ loadView”: loadView });
Example: presentationAnimationDidFinish
function presentationAnimationDidFinish() { //native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ presentationAnimationDidFinish”: presentationAnimationDidFinish });
Example: viewDidAppear
function viewDidAppear() { //native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ viewDidAppear”: viewDidAppear });
Example: viewWillAppear
function viewWillAppear() { //native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ viewWillAppear”: viewWillAppear });
Example: viewDidDisappear
function viewDidDisappear() { //native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ viewDidDisappear”: viewDidDisappear });
Example: viewWillDisappear
function viewWillDisappear() { //native bindings code } kony.shareExtensions.setExtensionsCallbacks({“ viewWillDisappear”: viewWillDisappear });
Return Values
None
Platform Availability
iOS