Open a different UIViewController when app is launched via SiriKit

旧时模样 提交于 2019-12-12 18:33:54

问题


I am trying to implement SiriKit in my iOS app. I want to open a different view controller when the app is launched through Siri.

How can I handle this type of operation in my app?


回答1:


You can do this, however, first you will have to setup SiriKit in your app, which is a bit of work with a long list of instructions: https://developer.apple.com/library/prerelease/content/documentation/Intents/Conceptual/SiriIntegrationGuide/index.html#//apple_ref/doc/uid/TP40016875-CH11-SW1 .

There's also a sample SiriKit App that Apple has put together called UnicornChat: https://developer.apple.com/library/content/samplecode/UnicornChat/Introduction/Intro.html

Once you have added your SiriKit App Extension and have handled your Intent properly, you will be able to send it to your app using a ResponseCode associated with your Intent. This will open your app, and you can catch that and send it to WhateverViewController by adding the following code to your app delegate:

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()
}


来源:https://stackoverflow.com/questions/40114075/open-a-different-uiviewcontroller-when-app-is-launched-via-sirikit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!