我正在使用以下函数来检测我的应用程序何时通过强制触摸快捷方式打开:
@available(iOS 9.0, *)
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
print("doing performActionForShortcutItem")
completionHandler(handleShortcut(shortcutItem))
}
在我的 AppDelegate.swift
文件中是否有另一种方法来检测何时在没有快捷方式的情况下打开应用程序?
最佳答案
当通过快捷方式激活时,(您的应用已经启动,但未激活)application:performActionForShortcutItem:completionHandler:
将被调用。
当通过快捷方式启动时,application:didFinishLaunchingWithOptions:
中的launchOptions
字典将包含一个键UIApplicationLaunchOptionsShortcutItemKey
.
如果该键不存在,则您的应用程序未通过快捷方式启动。
如果您测试该键的值不存在,您就会知道您的应用不是通过快捷方式启动的。
在 application:didFinishLaunchingWithOptions:
你需要这样的东西:
let launchedByShortcut = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] != nil
if (!launchedByShortcut) {
// the app wasn't launched via a shortcut
}
关于AppDelegate 中的 iOS 应用程序功能,用于在没有快捷方式的情况下打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36829898/