适用于iOS的Google登录:错误“无法使用”String“类型的索引下标类型'[String:AnyObject]'的值 [英] Google Sign-In for iOS: error "Cannot subscript a value of type '[String : AnyObject]' with an index of type 'String'"

查看:273
本文介绍了适用于iOS的Google登录:错误“无法使用”String“类型的索引下标类型'[String:AnyObject]'的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'无法下标类型为 [String,AnyObject] 的值,其索引类型为String',用于选项[UIApplicationOpenURLOptionsSourceApplicationKey] 。 Swift 2,iOS 9.x,使用CocoaPods安装Google登录。任何提示?

'Cannot subscript a value of type [String, AnyObject] with an index of type String' for options[UIApplicationOpenURLOptionsSourceApplicationKey]. Swift 2, iOS 9.x, Google Sign in installed using CocoaPods. Any hints?

func application(app: UIApplication, openURL url: NSURL, options:     [String : AnyObject]) -> Bool {
    return GIDSignIn.sharedInstance().handleURL(url,    sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey], annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}


推荐答案

功能在iOS 9.0之前

function before iOS 9.0

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation)
}

或使用您正在使用的方法,您可以像使用它一样( iOS 9.0及以上版本

or with the method you are using, you can using it like (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及以上 iOS 8.0到iOS 9.0

or to support both in iOS 9 and above and in 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)
}

这篇关于适用于iOS的Google登录:错误“无法使用”String“类型的索引下标类型'[String:AnyObject]'的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆