1

我已经成功地使用自定义意图在我的应用程序中制作了 siri 快捷方式的原型。我想为不同的快捷方式类型定义自定义 UI。例如,IntentA 将显示一张带有许多标签的高卡片,而 IntentB 将显示一张带有图像和一个标签的短卡片。

我在 MainInterface 故事板中使用的 IntentViewController 和意图定义文件之间的代码中看不到任何直接链接。

如果可能的话,我想在 MainInterface 故事板中定义 IntentAViewController 和 IntentBViewController 并相应地处理它们,但是我看不到我会告诉扩展为每个意图加载哪个视图控制器或故事板 ID。

如果不可能,那么完成多个意图 UI 的最佳实践是什么?(我还没有找到任何具有多个意图的教程)。

4

1 回答 1

1

我在 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 并设置约束)

于 2018-08-22T04:24:39.217 回答