Instantly share code, notes, and snippets.

Embed
What would you like to do?
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