[英]Ambiguous reference to member 'subscript' when using FBSDKApplicationDelegate
I have updated swift 3 and I found many errors. 我更新了swift 3,发现很多错误。 This is one of them : 这是其中之一:
Ambiguous reference to member 'subscript' 成员“下标”含糊不清
For the following line 对于以下行
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
}
I am not sure why I am getting this, does anyone else know ? 我不确定为什么要得到这个,其他人知道吗?
It works well in previous version 7.3.1 swift 2. 在早期版本7.3.1 swift 2中运行良好。
The type of the options
dictionary has changed from [String: AnyObject]
to [UIApplicationOpenURLOptionsKey : Any]
this means you should subscript with UIApplicationOpenURLOptionsKey
instead of a String
like you're doing now. options
字典的类型已从[String: AnyObject]
更改为[UIApplicationOpenURLOptionsKey : Any]
这意味着您应该使用UIApplicationOpenURLOptionsKey
下标而不是像现在这样的String
。
Try this: 尝试这个:
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)
}
This code extracts the keys you're looking for from the options
and passes them to the FBSDKApplicationDelegate
. 此代码从options
提取您要查找的键,并将它们传递给FBSDKApplicationDelegate
。 Note the usage of UIApplicationOpenURLOptionsKey.sourceApplication
and UIApplicationOpenURLOptionsKey.annotation
to access values in the options dictionary. 注意使用UIApplicationOpenURLOptionsKey.sourceApplication
和UIApplicationOpenURLOptionsKey.annotation
访问选项字典中的值。
This is how deal with with versions before and after iOS 9 with swift 3 and Xcode 8 这是使用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])
}
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.