Google Sign-In for iOS:错误“不能为索引types为”String“的types为”“的值添加下标
'对于options[UIApplicationOpenURLOptionsSourceApplicationKey]
[String, AnyObject]
为索引types为String的types[String, AnyObject]
下标。 Swift 2,iOS 9.x,Googlelogin使用CocoaPods进行安装。 任何提示?
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey], annotation: options[UIApplicationOpenURLOptionsAnnotationKey]) }
before iOS 9.0
function
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation) }
或者你正在使用的方法,你可以像使用它( Prior to iOS 9.0 and above
)
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:]) }
或者支持iOS 9 and above
和iOS 8.0 to iOS 9.0
@available(iOS 9.0, *) func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:]) } //for iOS 8, check availability @available(iOS, introduced=8.0, deprecated=9.0) func application(application: UIApplication,openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation) }
我发现我最近需要使用这个版本(即,Swift 3.x)。 我希望这可以帮助其他类似的编译错误。
return GIDSignIn.sharedInstance().handle( url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication.rawValue] as! String?, annotation: options[UIApplicationOpenURLOptionsKey.annotation.rawValue])