iosswiftamazon-web-servicesamazon-cognitoaws-amplify

Get user attributes AWS Amplify iOS SDK


I'm building an iOS app with the SDK Amplify so I have my users registered on AWS.

I already have my sign in/sign up flow working but the problem is that with the newest version of the SDK I have absolutely no idea of how can I get attributes of a registered user like his family name, email address etc...

With this new SDK everything seems to work around the AWSMobileClientclass but I see nothing from this class that can help me to get what I want.

The official documentation is anemic and doesn't cover or even point to my use case.

If somebody can give me some hint or even some good ressources I'll be very thankful!


Solution

  • Hi YoanGJ and future guests,

    Based on your comment you were looking for some sample code.

        AWSMobileClient.sharedInstance().getUserAttributes { (attributes, error) in
                if let attributes = attributes {
                    XCTAssertTrue(attributes.count == 3, "Expected 3 attributes for user.")
                    XCTAssertTrue(attributes["email_verified"] == "false", "Email should not be verified.")
                }else if let error = error {
                    XCTFail("Received un-expected error: \(error.localizedDescription)")
                }
                getAttrExpectation.fulfill()
    }
    

    This excerpt shows how you could call getUserAttributes and it comes from the integration tests found here.