2016-03-31 46 views
0

我有一个应用程序通过AWS Cognito使用Facebook提供程序成功登录。在登录身份后直接使用应用程序可以被检索,并且一切似乎都很好。IdentityId无在iOS App中使用AWS Cognito和Facebook登录

但是,经过一段时间(大约> 1小时)后,回到应用程序时,身份标识似乎没有被填写。奇怪的是,用户名仍然填写 - 只是不是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示例应用程序开始,包括AWS Mobile Hub自动生成的AWSMobileHubHelper框架。

我认为,问题是,会议没有被成功恢复为完成块中此功能重新推出的应用程序后,永远不会触发:在重新推出的应用

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函数以及执行初始登录的函数。标识对象是AWSIdentityManager类型的可选项,它是AWSMobileHubHelper框架中的包装器对象。 – 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) 
} 
相关问题