1

I am using AWS Cognito. The scenario is very simple. The user is prompt to enter a username, password, email address and phone number. The requirement is that when the user presses Sign Up button, a confirmation email is sent to the provided email address. After confirmation, he gets successfully signed up.

Things did till now:

Created Xcode project and installed the necessary pods.

Set up user pool by following AWS official docs.

Set up configuration by using the following code:

let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .######, identityPoolId: "######")
        let configuration = AWSServiceConfiguration(region: ######, credentialsProvider: credentialsProvider)

    AWSServiceManager.default().defaultServiceConfiguration = configuration

Used the following code for making users sign up.

@IBAction func SignUpClicked(_ sender: UIButton) {

        let userName = textFieldUsername.text
        let emailAddress = textFieldEmailAddress.text
        let phoneNo = textFieldPhoneNo.text
        let password = textFieldPassword.text
        let userPool = AWSCognitoIdentityUserPool(forKey: "myApp")

        let name = AWSCognitoIdentityUserAttributeType()
        name?.name = "name"
        name?.value = userName

        let phone = AWSCognitoIdentityUserAttributeType()
        phone?.name = "phone_number"
        phone?.value = phoneNo

        let email = AWSCognitoIdentityUserAttributeType()
        email?.name = "email"
        email?.value = emailAddress

        userPool.signUp(userName!, password: password!, userAttributes: [name!, phone!, email!], validationData: nil)
    }

What am I supposed to do next? Did I miss anything? I searched a lot but the content found was in objective c or related to signing up using identity providers. So it didn't help!

Farhan Yaseen
  • 2,507
  • 2
  • 22
  • 37
kinza
  • 535
  • 11
  • 31

2 Answers2

1

Swift examples are hard to come by but you can try these -

https://github.com/BruceBuckland/SignIn-awsmhh

AWS Cognito User Pools in iOS (Swift) app

BryceH
  • 2,740
  • 2
  • 21
  • 24
0

In Swift

You could use as a reference while writing code, you could also take a look codes which is both in Objective C and Swift.

CognitoYourUserPools-Sample References

https://github.com/awslabs/aws-sdk-ios-samples/tree/main/CognitoYourUserPools-Sample