对成员'下标'的模糊引用使用FBSDKApplicationDelegate时

时间:2016-09-15 08:51:46

标签: ios swift swift3

我更新了swift 3,发现了很多错误。这是其中之一:

  

对成员'下标'

的模糊引用

对于以下行

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as? String, annotation: options["UIApplicationOpenURLOptionsAnnotationKey"] as? String)

        return true
    }

我不知道为什么我会这样,其他人都知道吗?

在以前的版本7.3.1 swift 2中运行良好。

2 个答案:

答案 0 :(得分:3)

options字典的类型已从[String: AnyObject]更改为[UIApplicationOpenURLOptionsKey : Any],这意味着您应该使用UIApplicationOpenURLOptionsKey下标,而不是像您一样String&#39现在就做。

试试这个:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
        let annotation = options[UIApplicationOpenURLOptionsKey.annotation] else {
            return false
    }

    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url,
                                                                 sourceApplication: sourceApplication,
                                                                 annotation: annotation)

}

此代码从options中提取您要查找的密钥,并将其传递给FBSDKApplicationDelegate。请注意使用UIApplicationOpenURLOptionsKey.sourceApplicationUIApplicationOpenURLOptionsKey.annotation来访问选项词典中的值。

答案 1 :(得分:1)

这是如何使用swift 3和Xcode 8处理iOS 9之前和之后的版本

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {


    return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {


    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

}

希望它有所帮助!