判断iOS应用程序是否通过Siri启动

15

我找了很久,但没有发现...你知道有没有办法确定我的iOS应用是通过Siri还是用户点击应用程序图标启动的吗?

我需要知道这一点,因为我只想在从Siri启动我的应用程序时自动执行启动操作。

我想也许application:didFinishLaunchingWithOptions或其他API可以让我的应用程序知道它是如何启动的,但似乎并非如此(或者我只是错过了)。

是否有什么技巧可用,以便我在Apple发布官方/公共Siri API之前使用?


我认为Siri不是以API形式公开的。 - user2277872
如果应用程序知道它是通过Siri启动还是通过单击应用程序图标启动,我们有同样的问题。 - clearwater
3个回答

2
我唯一能提供的建议是检查作为 application:willFinishLaunchingWithOptions:application:didFinishLaunchingWithOptions: 的一部分传递的 launchOption 字典。有一个键声称列出了请求您的应用程序启动的应用程序名称,也许Siri会被列出:
来自苹果文档(位于这里): UIApplicationLaunchOptionsSourceApplicationKey 此键的存在标识请求启动您的应用程序的应用程序。此键的值是表示发出请求的应用程序的包ID的NSString对象。 此键还用于在名为UIApplicationDidFinishLaunchingNotification的通知的userInfo字典中访问相同的值。 在iOS 3.0及更高版本中可用。 声明在UIApplication.h中。

当我从SIRI启动应用程序时,既不会调用application:didFinishLaunchingWithOptions方法,也不会调用application:willFinishLaunchingWithOptions方法。 - Jayaprada
这些委托函数在我使用Siri启动应用程序时被调用。然而,启动选项参数为nil。 - Daniel Saidi

0
当我从Siri启动时,会调用application:didFinishLaunchingWithOptions方法。然而,我的launchOptions字典是空的。如果我使用URL scheme启动应用程序,我的launchOptions字典将包含适当的键。目前看来,似乎无法知道应用程序是否是从Siri启动的。

0

苹果提供的启动选项列表

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

这里是苹果文档中关于启动选项键的链接 Launch Options Keys
这里是关于官方/公共Siri API的Quora链接 Quora Link


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接