Swift 3 - How to start INStart Workout Intent?

I know there is a built-in template for it.

Go to the File menu and choose New> Target

Select iOS> Application Extensions from the left pane.

Now select the Intents extension.

This will create two new groups: YourExtension and YourExtensionUI. If you open the YoureExtension group, you will see IntentHandler.swift, which contains sample code for handling workouts.

Here you can find a simpler example:

class IntentHandler: INExtension, INSendMessageIntentHandling {
    override func handler(for intent: INIntent) -> AnyObject {
        // This is the default implementation.  If you want different objects to handle different intents,
        // you can override this and return the handler you want for that particular intent.
        return self
    }

    func handle(sendMessage intent: INSendMessageIntent, completion: (INSendMessageIntentResponse) -> Void) {
        print("Send message: " + (intent.content ?? "No message"))

        let response = INSendMessageIntentResponse(code: .success, userActivity: nil)
        completion(response)
    }
}

I did it, everything is fine.

Now my problem is to use INStart Workout Intent instead of INSendMessageIntent, how should I? Is there a built-in template for this purpose?

+4
1

, .

INStartWorkoutIntent, .

INSendMessageIntentHandling INStartWorkoutIntent.

public func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Swift.Void) {
    let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartWorkoutIntent.self))
    let response = INStartWorkoutIntentResponse(code: .continueInApp, userActivity: userActivity)
    completion(response)
}

:

Intents NSExtension, . , , , .

, . Siri , , .

, .

, , . Info.plist, .

enter image description here

, INSendPaymentIntent , . , , !

, , .

+6

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


All Articles