Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a different UIViewController when app is launched via SiriKit

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?

like image 679
Vivek Karthik Avatar asked Jan 26 '26 10:01

Vivek Karthik


1 Answers

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()
}
like image 162
matt.writes.code Avatar answered Jan 27 '26 23:01

matt.writes.code



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!