当通过SiriKit启动应用程序时,打开一个不同的UIViewController

我正在尝试在我的iOS应用程序中实现SiriKit。 我想通过 Siri启动应用程序时打开一个不同的视图控制器。

我怎样才能在我的应用程序中处理这种types的操作?

您可以这样做,但是,首先您必须在您的应用程序中设置SiriKit,这是一个长长的指令列表: https : //developer.apple.com/library/prerelease/content/documentation/Intents /Conceptual/SiriIntegrationGuide/index.html#//apple_ref/doc/uid/TP40016875-CH11-SW1 。

还有一个叫做UnicornChat的样本SiriKit应用程序: https : //developer.apple.com/library/content/samplecode/UnicornChat/Introduction/Intro.html

一旦添加了SiriKit应用程序扩展并正确处理了您的Intent,您就可以使用与您的Intent关联的ResponseCode将其发送到您的应用程序。 这将打开你的应用程序,你可以通过将下面的代码添加到你的应用程序委托来捕获它并发送到WhateverViewController:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { // implement to handle user activity created by Siri or by our SiriExtension let storyboard = UIStoryboard(name: "Main", bundle: nil) // Access the storyboard and fetch an instance of the view controller let viewController: WhateverViewController = storyboard.instantiateViewController(withIdentifier: "WhateverViewController") as! WhateverViewController window?.rootViewController = viewController window?.makeKeyAndVisible() }