我在 Apple 的 SoupChef 示例应用程序中找到了解决方案。由于只有一个主 IntentViewController 和一个 MainInterface 故事板,使用意图您应该检测意图类型并添加必要的视图控制器作为 IntentViewController 的子级。
来自 SoupChef 中的 IntentViewController:
/* Different UIs can be displayed depending if the intent is in the confirmation phase or the handle phase.
This example uses view controller containment to manage each of the different views via a dedicated view controller.
*/
if interaction.intentHandlingStatus == .ready {
let viewController = InvoiceViewController(for: intent)
attachChild(viewController)
completion(true, parameters, desiredSize)
} else if interaction.intentHandlingStatus == .success {
if let response = interaction.intentResponse as? OrderSoupIntentResponse {
let viewController = OrderConfirmedViewController(for: intent, with: response)
attachChild(viewController)
completion(true, parameters, desiredSize)
}
}
(其中 attach child 调用 addChild、addSubview、didMove 并设置约束)