从INUIHostedViewControlling
文档:
Intents UI 应用程序扩展与相应的 Intents 应用程序扩展协同工作。Intents 应用程序扩展处理意图并提供包含来自您的应用程序的数据的响应。Intents UI 应用扩展中的视图控制器以 INInteraction 对象的形式接收该数据,并使用它来配置其视图。
因此,在您的 IntentHandler 中:
func handle(intent: GetTimesIntent, completion: @escaping (GetTimesIntentResponse) -> Void) {
let activity = NSUserActivity(activityType: "com.your_company.your_identifier.get_times")
activity.userInfo?["times_time"] = "5:40"
activity.userInfo?["times_location"] = LatestLocation.City
let response = GetTimesIntentResponse(code: .success, userActivity: activity)
completion(response)
}
在你的 IntentViewController 中:
func configureView(for parameters: Set<INParameter>, of interaction: INInteraction, interactiveBehavior: INUIInteractiveBehavior, context: INUIHostedViewContext, completion: @escaping (Bool, Set<INParameter>, CGSize) -> Void) {
let data = interaction.intentResponse?.userActivity?.userInfo
let time = data?["times_time"] as? String ?? "No time"
let location = (data["times_location"] as? LatestLocation.City)?.name ?? "No city"
label.text = "\(location) at \(time)"
completion(true, parameters, self.desiredSize)
}