Original connection
1. Overview
Apple opened the SiriKit interface to third-party applications in iOS10. At present, QQ has been the first to fit Siri's message and call function. This means that in iOS10 you can just tell Siri to let it send you QQ messages and QQ calls, sounds cool?
What about the experience of using Siri with third-party apps? Which applications can access the Sirikit? What do I need to do to access SiriKit? This article will answer these questions for you.
Figure 1 using Siri to send QQ message effect display
2. SiriKit Introduction
We all know that Siri is the smart voice assistant in the iphone, so what is SiriKit? SiriKit is the development framework Apple provides for third-party apps that support Siri. In the official documentation, SiriKit will divide voice support for different scenarios into domain, and currently SiriKit supported domain includes: VoIP phone, send message, transfer, image search, online car booking, CarPlay and restaurant reservations, This means that if you have one of these features in your app, you can consider connecting these features to SiriKit.
When implementing SiriKit related functions, we do not need to really recognize the speech, and the recognition of the speech will be done by Siri. When Siri recognizes the voice, it abstracts the function that the voice wants to complete into a Intent object, and our access work is primarily about dealing with these Intent objects and not involving natural language processing (NLP) techniques.
There are some articles on the development of SiriKit online, but also refer to Apple's Official document SiriKit Programming Guide, this article focuses on the adaptation of QQ experience.
Fig. 2 Sirikit principle
3. SiriKit Access
To implement SiriKit's functionality requires adding Intents Extension's target in the Xcode project, like other Extension, Intents Extension is a plug-in that runs independently of the containing APP process , primarily for processing and confirming intent requests from Siri. If you want Siri to provide some custom interface when dealing with APP-related intent, then you need to add Intents UI Extension Target,intents UI Extension is also a standalone plug-in (so complete support SiriKit actually need to add two target, a bit of egg ache). The app Extension can be developed by referring to Apple's app Extension Programming Guide.
We take QQ in the message function as an example to illustrate the Sirikit access method:
First, we need to configure the Siri Intents we need to support in the Intents extentsion info.plist file, add intentssupported to Insendmessageintent, If you need to disable a feature on the lock screen, then add the corresponding item to the intentsrestrictedwhilelocked in intent,3 as shown.
Figure 3 Intent extentsion info.plist Configuration
SiriKit access is mainly divided into Intents Extension and Intents UI Extension two parts, the following are introduced respectively.
Intents Extension
When we say "hello to Wang Yizhan with QQ", the recognition will be done automatically by Siri and Siri will display the identified content in Siri's interface. As shown in 4, we can see that a complete message statement consists of four main parts:
app name : Tell Siri which App,siri to use to automatically identify the app's name based on the app's bundle DisplayName, without additional registration.
Send Message Intent: Tell Siri to use the function of sending messages, we found that the message is also able to identify, and specifically what words will be identified as the message intent Apple is not described in the document.
message recipient : Tell Siri who is the recipient of the message, "Wang Yizhan" is my QQ friend's nickname.
message content : Tell Siri what message you want to send, and the message here is "I'm angry".
Figure 4 Confirming the Send message interface
The application name and Intent are required, or Siri cannot abstract your "Intent". The latter two, if the default, we can ask the user to provide further data or ignore in the implementation. After the recognition is done, Siri abstracts the message content and receiver into a insendmessageintent Intent Extension that is passed to QQ.
We can also see from Figure 4 Siri accurately from my voice to identify my QQ friends nickname "Wang Yizhan" friends, but "Wang Yizhan" is not a common phrase, then how this is done? The secret is that when QQ runs we sync all of our QQ friends ' nicknames to Siri Cloud, so Siri can identify specific phrases to use for specific users, and detailed synchronization methods can refer to Invocabulary's setvocabularystrings:oftype: Method.
Each domain's functionality has a corresponding Intents in Siri, and each Intents corresponds to a specific handler protocol. For outgoing messages, the corresponding Intent and handler protocols are insendmessageintent and insendmessageintenthandling respectively. Just implement the relevant methods in the Insendmessageintenthandling protocol and use our insendmessageintenthandling when Siri resolves the insendmessageintent request object to handle the related outgoing message request. Specific Process 5:
Figure 5 Siri QQ Message Flow
1) resolverecipientsforsendmessage
Process and confirm the name of the recipient that Siri passed in from Intent, such as confirming that the name is currently in the QQ friends list, and giving resolution result back to Siri. Resolution result represents the results of the application being processed for intent, and table 1 lists several possible Resolution results for sending messages.
Table 1 Send resolution result
2) resolvecontent
Similar to the receiver's processing, the message content that Siri recognizes can be "decorated" in this method, and resolution result is fed back to Siri, such as QQ's emoji adaptation to special words like "angry" in some messages.
3) Confirmsendmessage
The function of this method is to confirm whether to send the message, you can do some authentication work in this step, authentication through the confirmation sent, otherwise canceled. Confirmation can be sent after the confirmation send interface, 4 shown. If you need to share data from the containing app, the specific implementation is referenced by the app Group's shared Container.
4) Handlesendmessage
4, when the user clicked the "Send" button or with the voice to send the instructions will eventually enter into this method, in this method we need to implement the logic of the message, send the success of the message can be adjusted to send a successful interface, 6.
Figure 6 Successful Message Delivery interface
Intents UI Extension
For Intent types that support custom interfaces, you can provide a more aesthetically pleasing custom interface in the Intents UI Extension. The Custom UI is relatively simple to implement, as is the case with IOS apps, which are implemented by Uiviewcontroller subclasses. We need to set the initial Viewcontroller in the Info.plist file of the Intents UI Extension or set the main storyboard, for different types of Intent interface display via child Vie Wcontrollers way to achieve differentiated interface display.
As shown in 7, when receiving response from Intents Extension, the system evokes Intents UI Extension and loads initial viewcontroller, via Inuihostedviewsiriprovi Ding protocol ConfigureWithInteraction:context:completion: Method can get intent, for example, in the message function, the message confirmation sent and sent after the success of this method will be callback once. Depending on the type and state of the Intent object, present the corresponding child Viewcontroller when receiving the callback for the relevant Intent to achieve a customized interface display.
It is important to note that the process of Intents UI Extension does not exit after the interface is destroyed, most likely just dormant in the background and then awakened the next time the response arrives.
Figure 7 Life cycle of an Intents UI extension
4. Summary
In general, although Apple has limited access to SiriKit this time, it is important for Siri to look at it from our adaptation experience. In addition, this is the first open interface for third-party applications in SiriKit, so there are inevitably some problems. We did encounter some SiriKit bugs in the development process, most of which were resolved after feedback to Apple, but Siri still has some flaws in language recognition, such as a mixed scene recognition of Chinese and English is still not good. Expect Siri to be more supportive of Chinese in the future, and hopefully Siri will be able to open more scenarios to third-party applications.
IOS10 SiriKit QQ Adaptation detailed