如何修复AWSCognito代码中的“ domainnsposixerrordomain code13权限被拒绝”运行时错误?

时间:2019-05-26 02:22:02

标签: ios swift runtime-error amazon-cognito aws-userpools

我遇到一个运行时错误,提示:

  

[NetworkInfo]信号强度查询返回错误:Error Domain = NSPOSIXErrorDomain代码= 13“权限被拒绝”,描述符:

在我的代码中声明了“任务”变量。我用注释标记了生成错误的行。

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

//create a pool
let configuration: AWSCognitoIdentityUserPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "6n3mb6nu0ls9ttfapkl69uuvd3", clientSecret: "7vlgp2ip3ihov4on7n0v4sti88sj6tfsobqlop6qu5t3db07bo6", poolId: "us-east-1_d0Y5gS66r")

AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: configuration, forKey: "AlarmMusic")
pool = AWSCognitoIdentityUserPool(forKey: "AlarmMusic")

let alertMessage = "Please register in order to be able to use this app:"

let alertController = UIAlertController(title: "Register", message: alertMessage, preferredStyle: .alert)

alertController.addTextField(configurationHandler: nil)
alertController.addTextField(configurationHandler: nil)
alertController.addTextField(configurationHandler: nil)

let actionOK = UIAlertAction(title: "OK", style: .cancel) {
    action in

    var attributes = [AWSCognitoIdentityUserAttributeType]()

    let email: AWSCognitoIdentityUserAttributeType = AWSCognitoIdentityUserAttributeType(name: "email", value: alertController.textFields?[2].text ?? "olea.gnolaum@gmail.com")

    attributes.append(email)

    let task: AWSTask<AWSCognitoIdentityUserPoolSignUpResponse> = self.pool.signUp(alertController.textFields?[0].text ?? "dbrower", password: alertController.textFields?[1].text ?? "Password@1989", userAttributes: attributes, validationData: nil).continueOnSuccessWith( block: {_ in return nil }) as! AWSTask<AWSCognitoIdentityUserPoolSignUpResponse> // ERROR OCCURS HERE!

    print("task=", task)

    let signUpResponse: AWSCognitoIdentityUserPoolSignUpResponse? = task.result

    print("signUpResponse=", signUpResponse as Any)

    let user: AWSCognitoIdentityUser? = signUpResponse?.user

    print("user=", user as Any)

}

alertController.addAction(actionOK)

self.present(alertController, animated: true, completion: nil)

以下是打印语句的调试窗口中的结果:

  

task =

     

signUpResponse =无

     

user = nil

我在AWS Cognito控制台中检查了我的用户池。全部检查完。我提供了用户池所需的所有必需信息。

这是泳池的屏幕截图:

enter image description here

此错误的原因是什么,为了解决它,我需要研究什么?

1 个答案:

答案 0 :(得分:0)

这是一个如何从Cognito吸引用户的小例子。

private func registerNewUser() {
  let userPool = ...
  let email = ...
  let password = ...
  let emailAttribute = AWSCognitoIdentityUserAttributeType(name: "email", value: email)
  let attributes:[AWSCognitoIdentityUserAttributeType] = [emailAttribute]

  userPool.signUp(email, password: password, userAttributes: attributes, validationData: nil).continueWith { (response) -> Any? in
    if response.error != nil {
      DispatchQueue.main.async {
        let alert = UIAlertController(title: "Error", message: (response.error! as NSError).userInfo["message"] as? String, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler:nil))
        self.present(alert, animated: true, completion: nil)
      }
    } else {
      self.user = response.result!.user
    }
    return nil
  }
}