Launch app from INExtension in SiriKit

2019-04-08 20:36发布

I want to use SiriKit to start a workout. Starting the workout requires opening the main app from the app extension.

The boilerplate that Apple provides for the INStartWorkoutIntentHandling handler is

func handle(startWorkout startWorkoutIntent: INStartWorkoutIntent, completion: (INStartWorkoutIntentResponse) -> Void) {
    let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartWorkoutIntent))
    let response = INStartWorkoutIntentResponse(code: .success, userActivity: userActivity)
    completion(response)
}

How can I open my own app from here? Something like myapp://workout?action=start&name=pushups This answer doesn't seem relevant, as I don't have a UIViewController with a extensionContext property for this extension type.

Last related bit: For the other actions (pause, end) I’d prefer to not open the main app, but to simply pause the workout which is running in the main app. I could use a similar custom URL to pause it, but that would open up the app which is an extra unnecessary step. Any good way to tell the main app to take a specific action from the INExtension without opening the app?

1条回答
神经病院院长
2楼-- · 2019-04-08 21:24

For posterity: turns out this was a phase-in of this functionality between Xcode 8 betas, it's been resolved in Xcode 8 beta 3. They added the .continueInApp code to INStartWorkoutIntentResponseCode in this version , but it wasn't there in Xcode 8 beta 2. This status code allows for the direct passing of NSUserActivity (no need to use a URL scheme).

查看更多
登录 后发表回答