SiriKit; How to display the answer to start Workout Intent?

IntentHandler Class :

import Intents

class IntentHandler: INExtension, INStartWorkoutIntentHandling {

    public func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {

        let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartWorkoutIntent.self))
        let response = INStartWorkoutIntentResponse(code: .continueInApp, userActivity: userActivity)
        completion(response)
    }

    //MARK: - INStartWorkoutIntentHandling

    func confirm(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Void) {

        completion(INStartWorkoutIntentResponse(code: .continueInApp, userActivity: nil))
    }
}

Apple's documentation says:

enter image description here

Siri opens the application, but I need to display the user interface from IntentUI. How to do it?

In other words: How to prepare for displaying the response, download the UI extension, prepare the interface and display it in code?

enter image description here

IntentViewController Class :

import IntentsUI

class IntentViewController: UIViewController, INUIHostedViewControlling {

    //MARK: - INUIHostedViewControlling

    func configure(with interaction: INInteraction!, context: INUIHostedViewContext, completion: ((CGSize) -> Void)!) {

        if let completion = completion {
            completion(self.desiredSize)
        }
    }

    var desiredSize: CGSize {
        return self.extensionContext!.hostedViewMaximumAllowedSize
    }
}

The base for this tutorial is really possible.

enter image description here

+4
source share
1 answer

Although Apple says here :

UI Intents, :



, , , , :

, INSendMessageIntentResponseCode INSentMessageIntentHandling:

public enum INSendMessageIntentResponseCode : Int {


    case unspecified

    case ready

    case inProgress

    case success

    case failure

    case failureRequiringAppLaunch

    case failureMessageServiceNotAvailable
}

INStartWorkoutIntentResponse INStartWorkoutIntentHandling:

public enum INStartWorkoutIntentResponseCode : Int {


    case unspecified

    case ready

    case continueInApp

    case failure

    case failureRequiringAppLaunch

    case failureOngoingWorkout

    case failureNoMatchingWorkout
}

.continueInApp, , , , : .success .inProgress

0

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


All Articles