1
我正试图在iOS中实施AWS Mobile Hub。点击“使用Google登录”按钮后,我会在身份浏览器上看到我的身份标识。这里没有问题。然后我想访问GIDGoogleUser。我初始化GIDGoogleUser,但我不能访问用户信息:AWS Mobile Hub Google身份验证iOS
let googleUser = GIDGoogleUser.init()
然后我检查是用户登录在与谷歌:在Xcode
if(AWSGoogleSignInProvider.init().isLoggedIn){
print("Success")
}else{
print("Authentication error")
}
我看到“认证错误”输出。我的错误在哪里?我怎样才能得到谷歌用户的电子邮件和全名?
AppDelegate.swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
AWSGoogleSignInProvider.sharedInstance().setScopes(["profile","email", "openid"])
AWSSignInManager.sharedInstance().register(
signInProvider: AWSGoogleSignInProvider.sharedInstance())
let didFinishLaunching = AWSSignInManager.sharedInstance().interceptApplication(
application, didFinishLaunchingWithOptions: launchOptions)
if (!isInitialized) {
AWSSignInManager.sharedInstance().resumeSession(completionHandler: {
(result: Any?, error: Error?) in
print("Result: \(result) \n Error:\(error)")
})
isInitialized = true
}
return didFinishLaunching
}
您应该使用google登录客户端的共享实例的'currentUser'属性来访问客户端信息。请参阅:https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#ac49bf5dabe7b89781cd58e69cb015651 –
不应该使用'AWSSignInManager.sharedInstance()。isLoggedIn'来检查登录吗? – Lawliet