如何为siri快捷方式的每个自定义意图使用不同的视图控制器?

时间:2018-08-20 17:50:49

标签: ios swift sirikit sirishortcuts

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

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

如果可能的话,我想在MainInterface故事板中定义IntentAViewController和IntentBViewController并进行相应的处理,但是我看不到告诉扩展程序要为每个意图加载哪个viewcontroller或Storyboard ID的地方。

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

1 个答案:

答案 0 :(得分:0)

我在Apple的SoupChef示例应用程序中找到了解决方案。由于只有一个主要的IntentViewController和一个MainInterface情节提要,因此,使用Intent时,您应该检测Intent类型,并将必要的视图控制器添加为IntentViewController的 child

在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) } } (其中附加子项调用addChild,addSubview,didMove并设置约束)