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