Determining whether iOS application was launched via Siri

谁说我不能喝 提交于 2019-12-09 14:46:01

问题


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 ?


回答1:


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.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/19149587/determining-whether-ios-application-was-launched-via-siri

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