4

IntentHandlerクラス:

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 のドキュメントには次のように記載されています。

ここに画像の説明を入力

Siri でアプリを開くのですが、IntentUI から UI を表示する必要があります。これを行う方法?

つまり、応答を表示する準備、インテント UI 拡張機能の読み込み、インターフェイスの準備、コードでの表示の方法は?

ここに画像の説明を入力

IntentViewControllerクラス:

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
    }
}

このチュートリアルに基づいて、実際に可能です。

ここに画像の説明を入力

4

1 に答える 1