Skip to content

Instantly share code, notes, and snippets.

@ewieberappc
Last active February 12, 2019 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ewieberappc/267dc348a714f0c58a950b2b8e9e4cfc to your computer and use it in GitHub Desktop.
Save ewieberappc/267dc348a714f0c58a950b2b8e9e4cfc to your computer and use it in GitHub Desktop.
Shortcuts in iOS 12 give Siri the hooks to incorporate deep app features into your Shortcut workflows. Here is an example.
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var lbl = Ti.UI.createLabel({
top: 150,
text: "I am waiting to do something."
});
var itemAttr = Ti.App.iOS.createSearchableItemAttributeSet({
itemContentType: Ti.App.iOS.UTTYPE_IMAGE,
title: 'Titanium Siri Shortcut Tutorial',
contentDescription: 'Tech Example \nOn: ' + (new Date().toLocaleString()),
});
var activity = Ti.App.iOS.createUserActivity({
activityType: "com.appc.shortcut",
title: 'Siri shortcut activity',
userInfo: {
msg: 'I did something!'
},
eligibleForSearch: true,
eligibleForPrediction: true,
persistentIdentifier: 'titanium_siri_identifier'
});
activity.addContentAttributeSet(itemAttr);
if (!activity.isSupported()) {
alert('User Activities are not supported on this device!');
} else {
activity.becomeCurrent();
Ti.App.iOS.addEventListener('continueactivity', function(e) {
Ti.API.info('continueactivity called');
if (e.activityType === "com.appc.shortcut" && e.userInfo.msg) {
alert(e.userInfo.msg);
}
});
}
win.add(lbl);
win.open();
Shortcuts in iOS 12 give Siri the hooks to incorporate deep app features into your Shortcut workflows. Here is an example.
1. Make sure you configure your tiapp.xml
2. You can then create a shortcut in Settings -> Siri & Search to perform an action in your app.
<ios>
<plist>
<dict>
<key>NSUserActivityTypes</key>
<array>
<string>com.appc.shortcut</string>
</array>
</dict>
</plist>
</ios>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment