我一直在寻找,但一直没有找到……你知道是否有办法确定我的 iOS 应用程序是由 Siri 还是由用户点击应用程序图标启动的?
我需要知道,因为我只想在从 Siri 启动我的应用程序时自动执行启动操作。
我在想也许application:didFinishLaunchingWithOptions或其他一些 API 可以让我的应用程序知道它是如何启动的,但情况似乎并非如此(或者我只是错过了它)。
知道在 Apple 发布一些官方/公共 Siri API 之前我可以使用一些技巧吗?
我一直在寻找,但一直没有找到……你知道是否有办法确定我的 iOS 应用程序是由 Siri 还是由用户点击应用程序图标启动的?
我需要知道,因为我只想在从 Siri 启动我的应用程序时自动执行启动操作。
我在想也许application:didFinishLaunchingWithOptions或其他一些 API 可以让我的应用程序知道它是如何启动的,但情况似乎并非如此(或者我只是错过了它)。
知道在 Apple 发布一些官方/公共 Siri API 之前我可以使用一些技巧吗?
我唯一能建议的是检查作为 and 的一部分传入的 launchOptionapplication:willFinishLaunchingWithOptions:
字典application:didFinishLaunchingWithOptions:
。
有一个键声称列出了请求您的应用程序启动的应用程序的名称,并且可能会列出 Siri:
来自位于此处的苹果文档:
UIApplicationLaunchOptionsSourceApplicationKey
此键的存在标识请求启动您的应用程序的应用程序。该键的值是一个 NSString 对象,它表示发出请求的应用程序的捆绑 ID。此键还用于访问名为 UIApplicationDidFinishLaunchingNotification 的通知的 userInfo 字典中的相同值。在 iOS 3.0 及更高版本中可用。在 UIApplication.h 中声明。
当我从 Siri 启动时,会调用 application:didFinishLaunchingWithOptions。但是,我的 launchOptions 字典是空的。如果我使用 URL 方案启动应用程序,我的 launchOptions 字典具有适当的键。目前,似乎无法知道该应用程序是否是从 Siri 启动的
苹果提供的启动选项列表
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 Link的 Quora 链接