I'm defining an app function using NSUserActivity, so it appears in Spotlight and Siri Shortcuts:
let activity = NSUserActivity(activityType: "com.myapp.siriTest")
activity.title = "Test function"
activity.userInfo = ["parameter" : "test"]
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(rawValue: "com.myapp.siriTest")
view.userActivity = activity
activity.becomeCurrent()
This part works fine, after calling the above function, the Test function button appears in Spotlight and Shortcuts. If i start the app from this intent, i can listen to it in my AppDelegate:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
print("app started from spotlight or shortcuts");
return true
}
Two question:
- if the app was started from a shortcut made with the Shortcuts app, is it possible to return a value back to the shortcut? For example i would return some text and my next step in the shortcut would send an sms message with that text.
- If i have more than one NSUserActivity, how can i differentiate them in my AppDelegate restorationHandler?