gpt4 book ai didi

swift - AWS Pool.Signup 不会在 Swift 3 的 block 内执行代码

转载 作者:行者123 更新时间:2023-11-30 13:01:30 33 4
gpt4 key购买 nike

好的,我开始使用 AWS Cognito,但陷入了用户注册...

这就是我的问题发生的地方:

    func register(userNameChosen:String, attributes:[AWSCognitoIdentityUserAttributeType]) {
let task = self.pool.signUp(userNameChosen, password: senhaTextField.text!, userAttributes: attributes, validationData: nil)

task.continue(with: AWSExecutor.default(), with: { (task) -> Any? in

if task.error != nil { //error occur
let alert:UIAlertController = UIAlertController(title: "Error", message: task.error?.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)



} else { //no error
print("no error")
let response:AWSCognitoIdentityUserPoolSignUpResponse = task.result! as AWSCognitoIdentityUserPoolSignUpResponse
self.user = response.user

if response.userConfirmed as! Int != AWSCognitoIdentityUserStatus.confirmed.rawValue { //user not confirmed via email
//setup para mandar atraves de Segue
self.sentTo = response.codeDeliveryDetails?.destination
self.performSegue(withIdentifier: "confirmSignUp", sender: self)

} else {
print("User already confirmed?")
self.navigationController?.popToRootViewController(animated: true) //back to login
}

}

return nil
}).waitUntilFinished()
}

问题是下面的代码

task.continue(with: AWSExecutor.default(), with: { (task) -> Any? in

不会执行...该应用程序已经与 AWS 进行了良好的通信。当我使用“登录可选”运行它时,即使未经身份验证,它也会获取 AWS token 。但是,当我在 Mobile Hub - Cognito 将“登录”设置为“必需”时,我收到以下消息(我认为这不是问题的一部分,因为在注册之前,您显然未经身份验证):

[26851:2009541] AWSiOSSDK v2.4.9 [Error] AWSIdentityProvider.m line:304 | __52-[AWSCognitoCredentialsProviderHelper getIdentityId]_block_invoke255 | GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.}]

或者

[26851:2009539] [] -[NWConcrete_tcp_connection dealloc] 1 
2016-10-04 21:02:33.759918 App Aws[26851:2009462] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0

最佳答案

我明白了。问题是,如果没有从 AWSTask 获得“响应”,它就不会进入该 block ,也不会抛出错误。

我的凭据配置有些错误,因此它无法附加到我的用户池。

这是我使用的代码,如果有人使用 Swift 3.0。

let serviceConfiguration:AWSServiceConfiguration = AWSServiceConfiguration.init(region: .usEast1, credentialsProvider: nil)

let configuration:AWSCognitoIdentityUserPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "PUT_YOUR_CLIENT_ID_HERE", clientSecret: PUT_YOUR_CLIENT_SECRET_HERE, poolId: "PUT_YOUR_POOL_ID_HERE")
AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: configuration, forKey: "UserPool")

AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration

如果您的客户端 key 为空,请使用 nil,不要使用“”。我强烈建议您使用客户端 key 。

关于swift - AWS Pool.Signup 不会在 Swift 3 的 block 内执行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39863529/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com