Launch the app from INExtension in SiriKit

I want to use SiriKit to start my workout. To start a workout, you must open the main application from the application extension.

The template that Apple provides for the handler INStartWorkoutIntentHandling,

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

How do I open my application? Something like myapp://workout?action=start&name=pushups This answer does not seem relevant, since I do not have extensions for this type of UIViewControllerproperty extensionContext.

Last bit: for other actions (pause, end), Id prefers not to open the main application, but simply to pause the workout performed in the main application. I could use a similar custom URL to pause it, but this will open the application, which is an unnecessary unnecessary step. Any good way to tell the main application to take a specific action from INExtension without opening the application?

+5
source share
2 answers

: , - Xcode 8, Xcode 8 beta 3. .continueInApp INStartWorkoutIntentResponseCode , wasn ' t Xcode 8 beta 2. NSUserActivity ( URL).

+1

:

let activity  = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
activity.webpageURL = URL(string: "https://mywebsite/...")        
completion(MyIntentResponse(code: .continueInApp, userActivity: activity))

AppDelegate

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        if let url = userActivity.webpageURL {
            handleDeeplink(url)
        }
    }
    return false
}
0

Source: https://habr.com/ru/post/1648850/


All Articles