2016-03-31 17 views
0

AWS Cognitoを使用してFacebookプロバイダを使用して正常にログインしているアプリがあります。ログイン後にアプリを直接使用すると、アイデンティティを取得でき、すべてがうまくいっているようです。IdentityIdはNilです。iOSアプリケーションでのAWS CognitoとFacebookログインを使用

しかし、アプリに戻ったときにある程度の時間(約1時間)が過ぎると、アイデンティティIDは記入されていないように見えます。奇妙なのは、ユーザー名がまだ記入されていることです。ちょうどidではありません。

let identity = self.getLoggedInIdentity() 
    let id = identity?.identityId  //this is nil 
    let username = identity?.userName //this still has a value 

    func getLoggedInIdentity() -> AWSIdentityManager? { 
     if userIsLoggedIn() { 
      return AWSIdentityManager.defaultIdentityManager() 
     } 

     return nil 
    } 

    func userIsLoggedIn() -> Bool { 
     let identityManager = AWSIdentityManager.defaultIdentityManager() 
     return identityManager.loggedIn 
    } 

私は自動的にAWSモバイルハブによって生成されたAWSMobileHubHelperフレームワークを含む、AWSのサンプルアプリの使用を開始。

私は問題がこの関数の内部完了ブロックアプリをリニューアルした後に発射することはありませんように、セッションが正常に再開されていないことであると信じて:

func didFinishLaunching(application: UIApplication, withOptions launchOptions: [NSObject : AnyObject]?) -> Bool { 
    print("didFinishLaunching:") 

    if (!isInitialized) { 
     print("AWSIdentityManager Attempt Resume Session") 
     AWSIdentityManager.defaultIdentityManager().resumeSessionWithCompletionHandler({(result: AnyObject?, error: NSError?) -> Void in 
       print("AWSIdentityManager Resume Session Result: \(result) \n Error:\(error)") 
     }) 
     isInitialized = true 
    } 
    let didFinishLaunching: Bool = AWSIdentityManager.defaultIdentityManager().interceptApplication(application, didFinishLaunchingWithOptions: launchOptions) 

    return didFinishLaunching 
} 

私は機能アプリをリニューアル時に呼び出されている確認しましたresumeSessionWithCompletionHandlerが呼び出されていますが、完了ハンドラが実行されることはありません。セッションが正常に再開されないと想定しています。参考のため

ここでは、最初のログイン機能も同様です:

@IBAction func handleFacebookLogin(sender: AnyObject) { 
    self.handleLoginWithSignInProvider(AWSFacebookSignInProvider.sharedInstance()) 
} 

func handleLoginWithSignInProvider(signInProvider: AWSSignInProvider) { 
    AWSIdentityManager.defaultIdentityManager().loginWithSignInProvider(signInProvider, completionHandler: {(result: AnyObject?, error: NSError?) -> Void in 
     // If no error reported by SignInProvider, discard the sign-in view controller. 
     if error == nil { 
      dispatch_async(dispatch_get_main_queue(),{ 
       self.dismissViewControllerAnimated(true, completion: nil) 
      }) 
     } 
     print("result = \(result), error = \(error)") 
    }) 
} 

任意のアイデア私が最初にログインし、他のAWSサービスに接続することができますが、いくつかの時間後にセッションを再開することができないであろう理由何か?

+0

' - getLoggedInIdentity'の実装と' identity'オブジェクトの定義を共有できますか?どのようにSDKからCognito IdentityIdを取得していますか? –

+0

私は、初期ログインを行う関数だけでなく、getLoggedInIdentity関数を含むように投稿を修正しました。 IDオブジェクトは、AWSMobileHubHelperフレームワークのラッパーオブジェクトであるAWSIdentityManager型のオプションです。 – outerstorm

+0

' - userIsLoggedIn'の定義はどうですか?表示されている問題を再現できるように、ログインフロー全体を確認する必要があります。 –

答えて

0

同じ問題がありました。 AppDelegateでこのように修正しました。 このコードを実装しましたか?

func application(application: UIApplication,openURL url: NSURL,sourceApplication: String?,annotation: AnyObject?) -> Bool { 
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
} 
関連する問題