7

最近在 Xcode 8 beta 6 (8S201h) 中,这已经成为一个问题。

 UIApplicationLaunchOptionsShortcutItemKey

这是错误:

在此处输入图像描述

还有谁有相同的问题吗?

var performShortcutDelegate = true
if let shortcutItem = launchOptions[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
    print("ok")
    self.shortcutItem = shortcutItem
    performShortcutDelegate = false
}
return performShortcutDelegate
4

3 回答 3

7

常量已更改(请参阅文档)。launchOptions在使用它包含的任何值之前,您还需要解包。

包含用于上下文的封闭函数。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    if let launchOptions = launchOptions {
        if #available(iOS 9.0, *) {
            if let shortcutItem = launchOptions[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
                print("Shortcut: \(shortcutItem)")
            }
        }
    }
    return true
}
于 2016-08-16T17:58:17.523 回答
1

函数参数中的 launchOptions Dictionary 类型已更改为 [UIApplicationLaunchOptionsKey: AnyObject]。

private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: AnyObject]?) -> Bool {

    ...

}
于 2016-09-12T11:44:28.733 回答
0

试试这个..它对我来说使用 Xcode8 , swift3

    //Check for ShortCutItem
    if #available(iOS 9.0, *) {
        if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
        }
    }
于 2016-09-22T09:22:19.480 回答