I've been looking forever, but haven't found… Do you know if there's a way to
determine whether my iOS app was launched by Siri or by the user tapping the app icon?
I need to know because I want to automate a startup action only when my app is
launched from Siri.
I was thinking that maybe application:didFinishLaunchingWithOptions or
some other API would allow my app to know how it was launched, but that doesn't
seem to be the case (or I just missed it).
Any idea if there's some trick available that I could use until Apple publishes
some official/public Siri API ?
The only thing I can suggest is to check the launchOption dictionary passed in as part of application:willFinishLaunchingWithOptions:
and application:didFinishLaunchingWithOptions:
.
There is one key that claims to list the name of the application that requested your apps launch and maybe Siri would be listed:
From the apple doc located here:
UIApplicationLaunchOptionsSourceApplicationKey
The presence of this key identifies the app that requested the launch of your app. The value of this key is an NSString object that represents the bundle ID of the app that made the request.
This key is also used to access the same value in the userInfo dictionary of the notification named UIApplicationDidFinishLaunchingNotification.
Available in iOS 3.0 and later.
Declared in UIApplication.h.
When I launch from Siri, application:didFinishLaunchingWithOptions is called. However, my launchOptions dictionary is empty. If I launch the app using a URL scheme, my launchOptions dictionary has the appropriate keys. At this time, it doesn't look like it's possible to know if the app was launched from Siri
List of launch options provided by apple
let UIApplicationLaunchOptionsURLKey: String
let UIApplicationLaunchOptionsSourceApplicationKey: String
let UIApplicationLaunchOptionsRemoteNotificationKey: String
let UIApplicationLaunchOptionsLocalNotificationKey: String
let UIApplicationLaunchOptionsAnnotationKey: String
let UIApplicationLaunchOptionsLocationKey: String
let UIApplicationLaunchOptionsNewsstandDownloadsKey: String
let UIApplicationLaunchOptionsBluetoothCentralsKey: String
let UIApplicationLaunchOptionsBluetoothPeripheralsKey: String
let UIApplicationLaunchOptionsShortcutItemKey: String
let UIApplicationLaunchOptionsUserActivityDictionaryKey: String
let UIApplicationLaunchOptionsUserActivityTypeKey: String
Here's the link to apple's documentation Launch Options Keys.
Here's the link to Quora regarding official/public Siri API Quora Link