AppDelegate 中的 iOS 应用程序功能,用于在没有快捷方式的情况下打开

标签 ios swift

我正在使用以下函数来检测我的应用程序何时通过强制触摸快捷方式打开:

@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/

相关文章:

ios - 简单游戏的应用程序提交文件夹/存档大小超过 200mb

objective-c - MKMapView addAnnotation 未立即添加注释

ios - 找不到广告网络适配器

ios - 如何以编程方式声明一次约束并在需要时在 Swift 中调用它?

swift - AlamoFire downloadProgress 完成处理程序异步/等待

ios - UITableView、registerClass 和 detailTextLabel——奇怪的行为

ios - 在 ios 中访问 @property 的 setMethod

ios - Restkit:执行我自己的 RKMapperOperation 时创建重复对象

ios - 获取黑白 UIImage(非灰度)

ios - Xcode 存档以前的版本