0

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:

  1. 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.
  2. If i have more than one NSUserActivity, how can i differentiate them in my AppDelegate restorationHandler?
passatgt
  • 4,234
  • 4
  • 40
  • 54

1 Answers1

0

I was curious about this but apparently it's impossible.

The output to Shortcuts is handled by the intent response in SiriKit.

One (hacky) workaround employed by apps like Jayson is to copy the output from NSUseractivity to the clipboard and then that can be accessed in Shortcuts using the "Get Clipboard" action.

Alternatively, add intents to your project.

mralexhay
  • 1,164
  • 1
  • 10
  • 16