Swift AWSCognito登录在注销后被阻止1次-“;在另一个线程中获取标识id失败或未成功';t在5秒内完成。”;
我试图在CognotController单例类中实现所有CognotSignup/Confirm/SignIn内容 我认为我的问题可能基于两个函数: 第一个函数是重新建立会话,从我的主视图控制器调用,主视图控制器接收回调,然后继续初始化会话或显示SignenViewController:Swift AWSCognito登录在注销后被阻止1次-“;在另一个线程中获取标识id失败或未成功';t在5秒内完成。”;,swift,amazon-web-services,swift3,amazon-cognito,Swift,Amazon Web Services,Swift3,Amazon Cognito,我试图在CognotController单例类中实现所有CognotSignup/Confirm/SignIn内容 我认为我的问题可能基于两个函数: 第一个函数是重新建立会话,从我的主视图控制器调用,主视图控制器接收回调,然后继续初始化会话或显示SignenViewController: func handleSignInToExistingSession() { if AWSIdentityManager.default().identityId != nil {
func handleSignInToExistingSession() {
if AWSIdentityManager.default().identityId != nil {
if AWSFacebookSignInProvider.sharedInstance().token().result == nil {
//print("AWSFacebookSignInProvider token: \(String(describing: AWSFacebookSignInProvider.sharedInstance().token().result))")
AWSFacebookSignInProvider.sharedInstance().reloadSession()
//print("AWSFacebookSignInProvider token reload possible: \(String(describing: AWSFacebookSignInProvider.sharedInstance().token().result))")
}
AWSSignInManager.sharedInstance().resumeSession(completionHandler: { (result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
if error != nil {
self.signInExistingSessionError?(error! as NSError)
} else if result != nil {
self.loginType = AWSFacebookSignInProvider.sharedInstance().isLoggedIn ? "facebook" : AWSCognitoUserPoolsSignInProvider.sharedInstance().isLoggedIn() ? "userpool" : "undefined"
self.signInExistingSessionCompleted?()
}
print("Result: \(String(describing: result)) \n Error:\(String(describing: error))")
})
})
} else {
self.signInExistingSessionError?(nil)
}
}
func handleSignInWithSignInProvider(_ signInProvider: AWSSignInProvider) {
AWSSignInManager.sharedInstance().login(signInProviderKey: signInProvider.identityProviderName, completionHandler: {(result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
if error != nil {
self.signInError?(error! as NSError)
} else {
self.signInCompleted?(true)
}
return
})
//print("result = \(String(describing: result)), error = \(String(describing: error))")
})
}
func handleLogout() {
if (AWSSignInManager.sharedInstance().isLoggedIn) {
AWSSignInManager.sharedInstance().logout(completionHandler: {(result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
self.presentSignedOutViewController()
self.presentLoadingView()
})
//SessionController.sharedInstance.resetSession()
})
// print("Logout Successful: \(signInProvider.getDisplayName)");
} else {
assert(false)
}
}
第二个功能是登录用户,从SignenViewController调用:
func handleSignInToExistingSession() {
if AWSIdentityManager.default().identityId != nil {
if AWSFacebookSignInProvider.sharedInstance().token().result == nil {
//print("AWSFacebookSignInProvider token: \(String(describing: AWSFacebookSignInProvider.sharedInstance().token().result))")
AWSFacebookSignInProvider.sharedInstance().reloadSession()
//print("AWSFacebookSignInProvider token reload possible: \(String(describing: AWSFacebookSignInProvider.sharedInstance().token().result))")
}
AWSSignInManager.sharedInstance().resumeSession(completionHandler: { (result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
if error != nil {
self.signInExistingSessionError?(error! as NSError)
} else if result != nil {
self.loginType = AWSFacebookSignInProvider.sharedInstance().isLoggedIn ? "facebook" : AWSCognitoUserPoolsSignInProvider.sharedInstance().isLoggedIn() ? "userpool" : "undefined"
self.signInExistingSessionCompleted?()
}
print("Result: \(String(describing: result)) \n Error:\(String(describing: error))")
})
})
} else {
self.signInExistingSessionError?(nil)
}
}
func handleSignInWithSignInProvider(_ signInProvider: AWSSignInProvider) {
AWSSignInManager.sharedInstance().login(signInProviderKey: signInProvider.identityProviderName, completionHandler: {(result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
if error != nil {
self.signInError?(error! as NSError)
} else {
self.signInCompleted?(true)
}
return
})
//print("result = \(String(describing: result)), error = \(String(describing: error))")
})
}
func handleLogout() {
if (AWSSignInManager.sharedInstance().isLoggedIn) {
AWSSignInManager.sharedInstance().logout(completionHandler: {(result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
self.presentSignedOutViewController()
self.presentLoadingView()
})
//SessionController.sharedInstance.resetSession()
})
// print("Logout Successful: \(signInProvider.getDisplayName)");
} else {
assert(false)
}
}
一切正常。但是,当我使用从mainViewController调用的此函数注销会话时:
func handleSignInToExistingSession() {
if AWSIdentityManager.default().identityId != nil {
if AWSFacebookSignInProvider.sharedInstance().token().result == nil {
//print("AWSFacebookSignInProvider token: \(String(describing: AWSFacebookSignInProvider.sharedInstance().token().result))")
AWSFacebookSignInProvider.sharedInstance().reloadSession()
//print("AWSFacebookSignInProvider token reload possible: \(String(describing: AWSFacebookSignInProvider.sharedInstance().token().result))")
}
AWSSignInManager.sharedInstance().resumeSession(completionHandler: { (result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
if error != nil {
self.signInExistingSessionError?(error! as NSError)
} else if result != nil {
self.loginType = AWSFacebookSignInProvider.sharedInstance().isLoggedIn ? "facebook" : AWSCognitoUserPoolsSignInProvider.sharedInstance().isLoggedIn() ? "userpool" : "undefined"
self.signInExistingSessionCompleted?()
}
print("Result: \(String(describing: result)) \n Error:\(String(describing: error))")
})
})
} else {
self.signInExistingSessionError?(nil)
}
}
func handleSignInWithSignInProvider(_ signInProvider: AWSSignInProvider) {
AWSSignInManager.sharedInstance().login(signInProviderKey: signInProvider.identityProviderName, completionHandler: {(result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
if error != nil {
self.signInError?(error! as NSError)
} else {
self.signInCompleted?(true)
}
return
})
//print("result = \(String(describing: result)), error = \(String(describing: error))")
})
}
func handleLogout() {
if (AWSSignInManager.sharedInstance().isLoggedIn) {
AWSSignInManager.sharedInstance().logout(completionHandler: {(result: Any?, authState: AWSIdentityManagerAuthState, error: Error?) in
DispatchQueue.main.async(execute: {
self.presentSignedOutViewController()
self.presentLoadingView()
})
//SessionController.sharedInstance.resetSession()
})
// print("Logout Successful: \(signInProvider.getDisplayName)");
} else {
assert(false)
}
}
并尝试从SignenView控制器重新登录。我收到消息:“在另一个线程中获取身份id失败或未在5秒内完成。”
完整消息是:Error Domain=com.amazonaws.service.cognitoidentity.AWSCognitoCredentialsProviderHelper Code=0“在另一个线程中获取标识id失败或未在5秒内完成。”
然后,如果我下次点击登录按钮,它就会登录。但是在注销后的第一次登录将不起作用
我找不到有关此错误消息的任何对我有意义的信息
感谢所有知道如何解决这个问题的人 我终于解决了这个问题 AWSMobileHub提供的示例项目有助于集成从AWSIdentityProfile继承的两个类
FacebookIdentityProfile
和UserPoolsIdentityProfile
。
这两个类都有一个函数load()
,该函数被称为自动登录其中一个提供程序。您应该在此功能中设置用户配置文件
我首先在这个函数中调用了一个AWSDynamoDBObjectMapper.default().load(…)
,检查用户是否已经在我的数据库中,并且不需要任何设置。我想这应该很好,因为它发生在注册之后。它在初次登录时运行良好。但是一旦用户注销并重新登录,AWSDynamoDBObjectMapper.default().load(…)
和cognito登录将并行执行,并且dynamodb会以某种方式阻止cognito
所以我要做的就是将dynamodb请求移出这个函数,并确保在登录完成之前不会调用它