在iOS应用程序中使用AWS Cognito和Facebook登录,IdentityId为零
我有一个通过AWS Cognito使用Facebook提供商成功登录的应用程序。虽然在登录后直接使用该应用程序,但可以检索到身份信息,一切似乎都很正常 但是,在返回应用程序一段时间后(大约>1小时),身份id似乎没有填写。奇怪的是,用户名仍然被填写——只是没有id在iOS应用程序中使用AWS Cognito和Facebook登录,IdentityId为零,ios,swift,amazon-web-services,aws-sdk,amazon-cognito,Ios,Swift,Amazon Web Services,Aws Sdk,Amazon Cognito,我有一个通过AWS Cognito使用Facebook提供商成功登录的应用程序。虽然在登录后直接使用该应用程序,但可以检索到身份信息,一切似乎都很正常 但是,在返回应用程序一段时间后(大约>1小时),身份id似乎没有填写。奇怪的是,用户名仍然被填写——只是没有id let identity = self.getLoggedInIdentity() let id = identity?.identityId //this is nil let username =
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服务,但在一段时间后无法恢复会话吗?我也有同样的问题。
我在AppDelegate上修复了这样的问题。
你实现了这个代码吗
func application(application: UIApplication,openURL url: NSURL,sourceApplication: String?,annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
您能否共享
-getLoggedInIdentity
的实现和标识
对象的定义?您是如何从SDK中获取Cognito Identity ID的?我修改了post以包含getLoggedInIdentity函数以及进行初始登录的函数。identity对象是AWSIdentityManager类型的可选对象,AWSIdentityManager是AWSMobileHubHelper框架中的包装器对象。关于-userIsLoggedIn
的定义如何?我们需要查看整个登录流程,以便我们可以尝试重现您看到的问题。我添加了-userIsLoggedIn函数,根据我与您的API的交互,这是一个版本混乱。我能请你们把各种API的版本都排好吗?我试过使用你的CoCoapod,但它们不是最新的,试过使用框架,那些还没有排好队。真的需要一个一致的(理想的cocoapods)API,它可以很好地协同工作!!!