SiriKit,如何显示开始的反应锻炼意图?
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 } }
基于这个教程是可能的。
虽然苹果在这里说:
如果您在以下域中支持意图,则可以提供Intents UI扩展:
消息
支付
乘坐预订
锻炼
我认为这是不可能的,因为负责开放式UI的响应不是为此准备的:
请看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