2017-09-13 126 views
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 
} 
+0

您应该使用google登录客户端的共享实例的'currentUser'属性来访问客户端信息。请参阅:https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in.html#ac49bf5dabe7b89781cd58e69cb015651 –

+0

不应该使用'AWSSignInManager.sharedInstance()。isLoggedIn'来检查登录吗? – Lawliet

回答

0

我一直试图在本周解决同样的问题,发现实际上不太可能与AWSGoogleSignInProvider做。

如果您浏览AWS Mobile SDK代码,您会发现它维护着一个内部声明的GIDGoogleUser单例实例。由于AWS SDK中的GIDGoogleUser是一个单独的类声明,因此在代码中调用GIDGoogleUser.init()会创建该单例的第二个实例。不好的事情发生在那个时候。遗憾的是,AWS开发工具包并未通过其API提供其GIDGoogleUser的内部实例。

我仍在寻找合理的解决方法。