kony.intentExtension Namespace

The kony.intentExtension namespace provides you with the ability to add Siri-related functionality For more information about what iMessage app extensions are and what you can use them for, refer the Apple developer documentation.

Intent extensions enable your iOS app to interface with Siri. An Intent contains the data that Siri gathered from the user. The callback functions that your app sets with the setExtensionsCallbacks Function process the input in the Intent.

By default, an Intent extension in Quantum Visualizerdoes not have a UI. However, Visualizer also enables you to create an IntentUI extension that does provide a UI. When you create an IntentUI with Quantum Visualizer, it generates an empty view. Whether you use an Intent extension or an IntentUI extension, you add your business logic to the extension's callback functions. Your JavaScript code accesses native functionality on iOS devices by using objects and invoking functions in the Native Functions API.

Quantum Visualizersupports following functionality in the Intent (or IntentUI) extensions.

  • VoIP calling
  • Messaging
  • Payments
  • Photo
  • Workouts
  • Ride booking

App Vocabulary

It is often the case that your app will have specific vocabulary words associated with it that you will need to teach to Siri when your app is installed. Some vocabulary words are needed by all users of your app. Others are user-specific. Your app can set the user-specific vocabulary by invoking the kony.vocabulary.setVocabularyStrings function. Your app can remove vocabulary words with the kony.vocabulary.removeAllVocabularyStrings function.

For vocabulary words that are needed by all of your users, you register a global vocabulary file when you install your app. For information on registering custom vocabulary words using a vocabulary file, refer the Apple developer documentation.

Granting Permissions

Apple specifies that users must manually grant apps permission to use the Apple SiriKit. For your app to request permission from the user, it must do the following.

  1. Include the NSSiriUsageDescription key in your iOS app’s Info.plist file. The value for this key is a string that describes what information your app shares with SiriKit. For example, a workout app might set the value to the string “Workout information will be sent to Siri.” Inclusion of this key in your Info.plist is required.
  2. Enable Siri under the Capabilities tab for Main app, as shown in the following illustration.
  3. Provide runtime permissions for your app by invoking functions in the Runtime Permissions API. An example of this is provided in the following sample code.
    var result =
        kony.application.checkPermission(kony.os.RESOURCE_SIRI, null);
    
    // If the app does not have the required permissions ...
    if (result.status == kony.application.PERMISSION_DENIED) {
        // See if the app can request permission.
        if (result.canRequestPermission) {
            kony.print("Requesting Permission");
            kony.application.requestPermission(
                kony.os.RESOURCE_SIRI,
                permissionStatusCallback,
                null);
        } else {
            kony.ui.Alert(
                "PERMISSION DENIED: Open Device Settings.",
                null,
                "Siri Error",
                null,
                null);
        }
    } else if (result.status == kony.application.PERMISSION_GRANTED) {
        kony.print("Permission Granted");
    } else if (result.status == kony.application.PERMISSION_RESTRICTED) {
        kony.print("Permission Restricted");
    }
    
    function permissionStatusCallback(response) {
        if (response.status == kony.application.PERMISSION_GRANTED) {
            kony.print("Permission Granted");
        } else if (result.status == kony.application.PERMISSION_DENIED) {
            kony.print("Permission Denied");
        }
    }

Configuring Your Project for Intent Extensions

To configure your project for Intent extensions, you must perform the following mandatory steps.

  1. Enable ‘Siri’ under Capabilities for KRelease, KDebug Target in your Xcode Project.
  2. Include the NSSiriUsageDescription key in your iOS app’s Info.plist file for authorization.
  3. Specify the intents that your extension supports.
  4. In Xcode, select the Info.plist file of your Intents extension.
  5. Expand the NSExtension and NSExtensionAttributes keys to reveal the IntentsSupported and IntentsRestrictedWhileLocked keys.
  6. In the IntentsSupported key, add a String item for each intent that the extension handles. Set the value of each item to the class name of the intent.This key is required. You can support all of the intents in a given domain or only some of them, and a single extension can support multiple domains.
  7. In the IntentsRestrictedWhileLocked key, add a String item for each intent for which you require the device to be unlocked. Set the value of each item to the class name of the intent. This key is optional. Some intents, such as those involving financial transactions, always require the user’s device to be unlocked. You can use this key to augment the default list with intents that do not require an unlocked device by default.

Functions

The kony.intentExtension namespace provides the following function.