The Entire Process of Integrating Siri in the Third-Party Apps
Ever since Apple introduced its voice recognition assistant in 2011, the Artificial Intelligence (AI) based technology is going great guns. Following its successful launch, there were further enhancements and the WWDC Apple Event in 2017 saw the vital announcement of Siri integration with the third-party apps. However, this integration was limited to a few apps only such as messaging, payments, photo search, and booking apps. With the release of iOS 11, this list was further extended and one also witnessed the introduction of SiriKit. The introduction of SiriKit has added another feather into the cap. This framework has simplified the task of the iOS app developers to a great extent. It has become much easier to add new customized features to Siri, which is then integrated with the third-party apps. But it must be noted that you can get access to the benefits of SiriKit only if you are using iOS 10 or the advanced versions. One of the major factors that have led to the increment of the popularity of Siri is that the users’ just need to give a voice command and the task is performed. So, whether it is paying a monthly electric bill, or adding a new item into your online shopping cart, use voice command to get the work done. If we talk about the stat and figures, then according to Business Insider, about 70% of the iPhone users agree that they have used Siri sometimes or rarely. On the other hand, Statista, reports that 51% of Americans comprehensively and clearly understand the usage of Siri in their devices. In fact, the addition of functionality has indeed become easier as it needs to be implemented with the help of SiriKit. Here we would have a detailed discussion on how to integrate the Siri with a third-party app. Selecting a Particular Niche First things first, you need to choose a particular domain or niche or the app based on the app activity. However, it must be noted that SiriKit does not support all app domains; so, you have limited choice. For example, you can choose messaging apps, payment, workouts, image searching, climate and radio etc. You can find more options from the SiriKit Programming Guide. Siri makes use of the intents to perform the tasks. When the user wants Siri to fulfil a task, it would send the user intent with other details to the handler of that intent. The intent comprise of its own protocol, which the manager incorporates for that intent. You also get the advantage of expanding the default User Interface in the Siri window. Building a Cocoa Touch Framework Once you have chosen the app domain, the next task is to build a Cocoa Touch framework for the application. You should remember to receive the Siri support through the integration of the Intents Extension and that you cannot use the codes directly. Therefore, you need to take the help of the Cocoa Touch framework. For this, you have to first visit the Xcode menu and then choose File–>New–>Target. This will set up the Cocoa Touch Framework. In the next step, you would be asked to choose the template that you want to use for the target. Then you would get across a window where you can change the template option and name your framework. You need to verify carefully that the framework contains the similar project and check the insert in application field. The Addition of Classes to Framework Upon the completion of the above task, the next job in hand is adding the classes to the framework. You can add the classes, which highlight your domain of the user request sending the requests for the backend development process. In case, your class is already integrated move on to the name of your framework. Now, you need to eliminate the class from the key target and add them manually to the framework target. The Integration of the Intent Handler Now we have reached the most crucial step of integrating the Siri in third-party apps. Here we have to implement the intent handler. But before you go into the details, the first job in hand is to add an intent extension target to your app. You can do this by the following process- File–>New–>Target. Next choose the Intents Extension. At this stage you will be required to fill out a name such as the SiriIntentExtension.” Now you also have to add a few data to the Info.plist” file of the “SiriIntentExtension” <key>NSExtension</key> <dict> <key>NSExtensionAttributes</key> <dict> <key>IntentsSupported</key> <array> <string>INSendMessageIntent</string> </array> </dict> <key>NSExtensionPointIdentifier</key> <string>com.apple.intents-service</string> <key>NSExtensionPrincipalClass</key> <string>$(PRODUCT_MODULE_NAME).IntentHandler</string> </dict> You need to denote the supported intents list. In case you are reducing the accessibility of the intents for the locked devices, it is important to detail out the restricted intents list with the help of IntentsRestrictedWhileLocked button. On the other hand, we have the NSExtensionPrincipalClass key offering the name of the class in the IntentsExtension deciding the name of the handler for the intent. You can name this class as IntentHandler. This is an easy step to follow: import Intents class IntentHandler: INExtension { override func handler(for intent: INIntent) -> Any? { return MessagesIntentHandler() } } As we can see there is a return of instance of MessagesIntentHandler for the specified intent as we focused only on a single intent type. But in case of various intents, you need to check the intent handler for if intent is INSendMessageIntent { return MessagesIntentHandler() } The name MessagesIntentHandler is a class and the happening place. So if you want to incorporate this class you can follow the code below. class MessagesIntentHandler: NSObject, INSendMessageIntentHandling { … } You need the support of NSObjectProtocol if you want to run the INSendMessageIntentHandling protocol. This protocol has one compulsory and four other optional functions. If we talk about the four optional functions then these are: The first is known as the resolveRecipients(forSendMessage:with:) where you have to specify the name of the recipient for the given intent. If you are using single intent,
The Entire Process of Integrating Siri in the Third-Party Apps Read More »