This following tutorial will guide you through the process of creating a new iOS extension and in this case also shows you how to configure your app to communicate with Siri using the Intents framework. This framework is different to some other extensions as it requires special capabilities, provisioning profiles, and privacy-permissions. This document will show you how to do that as well.
The repository for this tutorial can be found open-source on Github .
Step-by-step guide
- Create a native Titanium App with
appc new -p ios,
using Appcelerator Studio, or use your existing project. - The name of the example is TestApp, the
<id>
in tiapp.xml will be something likecom.appc.testapp
. - Open Xcode and create new project:
File/New Project/Other/Empty
- Name it
TestApp
for this tutorial. - Use
File/New/Target/Application Extension/Intents Extension
to create the extension target. By default, Xcode will add some demo code to handle Message Intents, but you can implement whatever Intent extension you want here.
- Name the extension
testapp
and change the "Organization Identifier" tocom.appc.testapp
so that the "Bundle Identifier" iscom.appc.testapp.testapp
- You can also suffix it to something likesiriextension
, but let's keeps it simple for now.
- If you wish, you can activate scheme when prompted, but it doesn't matter because we won't need to open the standalone Xcode-project while building.
- Create a folder called
extensions
in the Titanium project (root) folder and copy the Xcode extension project into it. -
In the
tiapp.xml
, include the following properties in the<ios>
section of it:tiapp.xml<
extensions
>
<
extension
projectPath
=
"extensions/TestApp/TestApp.xcodeproj"
>
<
target
name
=
"testapp"
>
<!-- or "siriextension" if you name the target differently -->
<
provisioning-profiles
>
<
device
>INSERT YOUR EXTENSION PROVISIONING PROFILE ID HERE</
device
>
<
dist-appstore
/>
<
dist-adhoc
/>
</
provisioning-profiles
>
</
target
>
</
extension
>
</
extensions
>
- Create or edit your App-ID in the iOS Developer Center to include the "SiriKit" capability, just like you would
do with "Access Groups" or "Push Notifications" for
other platform-services. Create one app with a wildcard identifier and
one without (e.g.
com.appc.testapp.*
andcom.appc.testapp
). The first one is linked in the<provisioning-profiles>
section of the target, the latter one is used to build the main target (your app) to the device. Note that SiriKit is supported in the Simulator by Apple, because it doesn't support Siri so far (Status: iOS 10 / November 2016).
- Generate two provisioning profiles (one for your main app and one for the Siri target) in the "Provisioning Profiles" section.
-
Add the following to the plist-section of your
tiapp.xml
(<tiapp>
><ios>
><plist>
):tiapp.xml<
key
>NSSiriUsageDescription</
key
>
<
string
>Can we use Siri to do great stuff?</
string
>
-
Create a file called
TestApp.entitlements
in your Titanium project root. Note: if you also use push-entitlements, copy those keys over there as well since it will override the CLI-generated key and paste the following into it:TestApp.entitlements<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<
plist
version
=
"1.0"
>
<
dict
>
<
key
>com.apple.developer.siri</
key
>
<
true
/>
</
dict
>
</
plist
>
-
You made it!! Use
appc run -p ios -T device
or Appcelerator Studio to run your app on the device. Remember that iOS currently does not support Siri on the Simulator. -
You can test the changes by talking to Siri:
Send a Message with TestApp
It will know that your app uses the Intent Extension for handling messages and will ask you for Siri permissions by displaying the message you specified in your plist. You can also change the UI of the Intent by changing the storyboard in your "testappUI" target or specify multiple intents. Just create another target and link it the same way as we did above.
And finally, use Hyperloop or a native module to handle the Intent's responses. Since there dozens of classes and delegates to implement here, you should look for the ones your Intent uses and it will be notified by your extension. This guide may be updated with some samples for that as well, but you can also check some of the existing guides for that:
- https://developer.apple.com/library/content/documentation/Intents/Conceptual/SiriIntegrationGuide/SiriDomains.html#//apple_ref/doc/uid/TP40016875-CH9-SW11
- http://jamesonquave.com/blog/adding-siri-to-ios-10-apps-in-swift-tutorial/
- http://willowtreeapps.com/blog/a-deeper-look-at-sirikit-for-ios-10/
Code strong!