Introduction
In iOS9 you can not do any development or integration with Siri, it is very closed. However with NSUserActivity or CoreSpotlight, since Siri accesses the same search engine, it can launch your app if your app appears in the search results brought up by Siri, but it’s very limited and you have no ability to configure it.
iOS 10 finally allows third-parties to integrate with Siri, however it is still limited. Siri integration works by having Domains and Intents, however these Domain’s and Intent’s are limited. At the moment the only Domains you can work with are:
- Messaging (think WeChat)
- Ride Booking (think Uber)
- Photo Search
- Payments
- VOIP Calling
- Workouts
- Climate and Radio (specifically for CarPlay)
- (in the documentation they also mention for Maps only) Restaurant Reservations.
If your app doesn’t fit into any of these domains, then your app won’t integrate with Siri. However as with other new feature releases from Apple, I suspect these groups will expand over time.
Getting Started
First you need to have iOS 10 SDK’s that involves XCode 8, which is currently in beta. Xamarin already has the early preview of iOS 10 which includes SiriKit, which will be available in the alpha channel.
Set Entitlements
- Go to developer.apple.com
- Edit your App ID to enable SiriKit
- You will need to regenerate and download new provisioning profiles if you are modifying an existing App Identifier.
Create Extension
Next you need to create the Intents Extension. In the future you will go and create a new project, select extensions under iOS and there will be Intents Extension. Xamarin Preview does not seem to have this yet. Hence below is an image of the Xcode selection as a placeholder until I can get a Xamarin one.
What I did is converted the Intents Extension over to C# in my SiriKitTest sample project, if you want to see the code that it generates.
Intents Supported
If you go to your info.plist you will see that it shows the intents supported. By default mine added INSendMessageIntent. These are predefined intents and you can add more to the list. For a list of supported intents have a look at Intent Domains.
Handling Intent
In your extension create an IntentHandler as below.
public class IntentHandler: INExtension, IINSendMessageIntentHandling { public IntentHandler() {} public void HandleSendMessage(INSendMessageIntent intent, Action<INSendMessageIntentResponse> completion) { var userActivity = new NSUserActivity(activityType: "INSendMessageIntent"); var response = new INSendMessageIntentResponse(code: success, userActivity: userActivity); completion(response); } // Issue: no overrides for ResolveContent public override ResolveContent(INSendMessageIntent intent, Action<INStringResolutionResult> completion) { if (intent.Content != "") { completion(INStringResolutionResult.GetSuccess(intent.Content)); } else { // Issue: NeedsValue returns the base type and not derived type. completion(INStringResolutionResult.NeedsValue); } } }
For more information you might want to look at Introduction to SiriKit by Apple or Understanding SiriKit Concepts by Xamarin. I will revisit this post once the final release comes out.
Cross platform mobile developer who loves delving deep into frameworks and solving problems.