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))
}
}
苹果文档说:
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
}
}
基于本教程,这确实是可能的。