2

I am getting a runtime error that says:

[NetworkInfo] Signal strength query returned error: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied", descriptor:

in my code where the variable "task" is declared. I marked the line that generates the error with a comment.

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)

Here are the results in the debug window of the print statements:

task=

signUpResponse= nil

user= nil

I checked my user pool in AWS Cognito Console. It all checks out. I provided all the required information the user pool requires.

Here's a screenshot of the pool:

enter image description here

What is the cause of this error, and what do I need to look into in order to fix it?

daniel
  • 1,446
  • 3
  • 29
  • 65
  • Check [this](https://stackoverflow.com/questions/53526194/how-to-troubleshoot-resolve-signal-strength-query-returned-error-logs-that-are). You can safely ignore it. I've been seeing it in one of my projects for a long time and it has no effect. – Don May 26 '19 at 02:46
  • @Don Yes. I found where it says in different places that the error message is a sort of unneeded relic. However, I am getting a nil for that print statement for "user". I also checked in AWS Cognito Console, and it doesn't show that a user had been created, so I thought maybe the error message is legitimate. – daniel May 26 '19 at 02:50
  • @Don I checked and found that even though a task object is created, the result property of the task object is nil. – daniel May 26 '19 at 02:57
  • Sorry, I didn't read that closely. I just recognized the error message and responded. If you're using real data (clientId, clientSecret, etc.), you should delete this question and open a new one with dummy data. – Don May 26 '19 at 03:04
  • 1
    @Don I'm sure you read it closely the first time. I added the print statements and the print results when I edited it after you made your last comment. – daniel May 26 '19 at 03:06
  • @Don The block argument of the continueOnSuccessWith method never executes. I just checked by adding print statements in that block. – daniel May 26 '19 at 03:09
  • @Daniel Brower did you find a fix ? I have the same bug – Vi. Jul 18 '19 at 07:58
  • @Vi. Sorry. I don’t even remember this problem. It’s been so long ago. – daniel Jul 18 '19 at 15:28

1 Answers1

0

Here's a small example of how to get the user from 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
  }
}
Don
  • 479
  • 1
  • 4
  • 7