![](/img/trans.png)
[英]Getting descriptive login error messages in iOS app using AWS Cognito
[英]IdentityId is Nil Using AWS Cognito and Facebook Login in iOS App
我有一個可以通過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示例應用程序開始,其中包括由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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.