2017-09-13 1 views
1

iOS에서 AWS 모바일 허브를 구현하려고합니다. "Google로 로그인"버튼을 클릭하면 ID 브라우저에서 내 ID를 볼 수 있습니다. 여기에는 문제가 없습니다. 그런 다음 GIDGoogleUser에 액세스하려고합니다. 사용자가 구글에 로그인 한 AWS 모바일 허브 Google 인증 iOS

let googleUser = GIDGoogleUser.init() 

그럼 내가 확인 :

if(AWSGoogleSignInProvider.init().isLoggedIn){ 
     print("Success") 
}else{ 
     print("Authentication error") 
} 

내가 볼 '인증 오류'출력 엑스 코드에서 나는 GIDGoogleUser을 초기화하지만 사용자 정보에 액세스 할 수 없습니다. 내 실수는 어디 갔지? 그리고 어떻게하면 Google 사용자의 이메일과 이름을 얻을 수 있습니까?

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 SDK는 API를 통해 GIDGoogleUser의 내부 인스턴스를 사용할 수 없습니다.

나는 여전히 합리적인 해결책을 찾고 있습니다.