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

3

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

我该如何在我的应用程序中处理这种操作?


2
嗨,Vivek,欢迎来到StackOverflow!目前这个问题对于StackOverflow社区来说过于宽泛。请展示一下您在解决这个问题时所做的研究和尝试,并尝试让您的问题更加具体。同时,建议您阅读一下苹果关于SiriKit、AppDelegate和UIViewController的文档。 - Sam Spencer
1个回答

1
你可以这样做,但首先你需要在你的应用程序中设置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应用程序扩展并正确处理了你的意图,你将能够使用与你的意图相关联的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()
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接