Page updated Nov 9, 2023

Identify user

Amplify iOS v1 is now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Swift to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for iOS, you can access the documentation here.

This call sends information that you have specified about the user to Amazon Pinpoint. This could be an authenticated user. If the user is signed in through Amplify.Auth.signIn, then you can retrieve the current user and use it with Analytics. You can also provide location information in AnalyticsUserProfile.Location.

func identifyUser() { guard let user = Amplify.Auth.getCurrentUser() else { print("Could not get user, perhaps the user is not signed in") return } let location = AnalyticsUserProfile.Location(latitude: 47.606209, longitude: -122.332069, postalCode: "98122", city: "Seattle", region: "WA", country: "USA") let properties: AnalyticsProperties = ["phoneNumber": "+11234567890", "age": 25] let userProfile = AnalyticsUserProfile(name: username, email: "name@example.com", location: location, properties: properties) Amplify.Analytics.identifyUser(user.userId, withProfile: userProfile) }
1func identifyUser() {
2
3 guard let user = Amplify.Auth.getCurrentUser() else {
4 print("Could not get user, perhaps the user is not signed in")
5 return
6 }
7
8 let location = AnalyticsUserProfile.Location(latitude: 47.606209,
9 longitude: -122.332069,
10 postalCode: "98122",
11 city: "Seattle",
12 region: "WA",
13 country: "USA")
14
15 let properties: AnalyticsProperties = ["phoneNumber": "+11234567890", "age": 25]
16
17 let userProfile = AnalyticsUserProfile(name: username,
18 email: "name@example.com",
19 location: location,
20 properties: properties)
21
22 Amplify.Analytics.identifyUser(user.userId, withProfile: userProfile)
23
24}