【发布时间】:2016-12-08 18:36:23
【问题描述】:
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
}
}
基于this 教程确实可以。
【问题讨论】:
-
只是为了确保您的 Info.plist 中是否有 NSExtensionMainStoryboard 的 MainInterface 值?
-
是的,它嵌套在
NSExtension键中,它包含在我的IntentTimerUI扩展中,不适用于IntentTimer。 -
IntentsSupported键怎么样? -
是的,它嵌套在
NSExtensionAttributes中:IntentTimer和IntentTimerUI。 -
尝试改成
INStartWorkoutIntentonly