Identify users in iOS SDK
Adapty creates an internal profile ID for every user. However, if you have your own authentication system, you should set your own Customer User ID. You can find users by their Customer User ID in the Profiles section and use it in the server-side API, which will be sent to all integrations.
Set customer user ID on configuration
If you have a user ID during configuration, just pass it as customerUserId
parameter to .activate()
method:
- Swift
- Swift-Callback
// In your AppDelegate class:
import Adapty
let configurationBuilder =
AdaptyConfiguration
.builder(withAPIKey: "PUBLIC_SDK_KEY")
.with(customerUserId: "YOUR_USER_ID")
do {
try await Adapty.activate(with: configurationBuilder.build())
} catch {
// handle the error
}
// In your AppDelegate class:
import Adapty
let configurationBuilder =
AdaptyConfiguration
.builder(withAPIKey: "PUBLIC_SDK_KEY")
.with(customerUserId: "YOUR_USER_ID")
Adapty.activate(with: configurationBuilder.build()) { error in
// handle the error
}
Want to see a real-world example of how Adapty SDK is integrated into a mobile app? Check out our sample apps, which demonstrate the full setup, including displaying paywalls, making purchases, and other basic functionality.
Set customer user ID after configuration
If you don't have a user ID in the SDK configuration, you can set it later at any time with the .identify()
method. The most common cases for using this method are after registration or authorization, when the user switches from being an anonymous user to an authenticated user.
- Swift
- Swift-Callback
do {
try await Adapty.identify("YOUR_USER_ID")
} catch {
// handle the error
}
Adapty.identify("YOUR_USER_ID") { error in
if let error {
// handle the error
}
}
Request parameters:
- Customer User ID (required): a string user identifier.
Resubmitting of significant user data
In some cases, such as when a user logs into their account again, Adapty's servers already have information about that user. In these scenarios, the Adapty SDK will automatically switch to work with the new user. If you passed any data to the anonymous user, such as custom attributes or attributions from third-party networks, you should resubmit that data for the identified user.
It's also important to note that you should re-request all paywalls and products after identifying the user, as the new user's data may be different.
Logging out and logging in
You can logout the user anytime by calling .logout()
method:
- Swift
- Swift-Callback
do {
try await Adapty.logout()
} catch {
// handle the error
}
Adapty.logout { error in
if error == nil {
// successful logout
}
}
You can then login the user using .identify()
method.
Set appAccountToken
The appAccountToken
is a UUID that helps Apple's StoreKit 2 identify users across app installations and devices.
Starting from the Adapty iOS SDK 3.10.2, you can pass the appAccountToken
when configuring the SDK or when identifying a user:
- Swift
- Swift-Callback
// During configuration:
let configurationBuilder =
AdaptyConfiguration
.builder(withAPIKey: "PUBLIC_SDK_KEY")
.with(customerUserId: "YOUR_USER_ID", withAppAccountToken: UUID())
do {
try await Adapty.activate(with: configurationBuilder.build())
} catch {
// handle the error
}
// Or when identifying a user:
do {
try await Adapty.identify("YOUR_USER_ID", withAppAccountToken: UUID())
} catch {
// handle the error
}
// During configuration:
let configurationBuilder =
AdaptyConfiguration
.builder(withAPIKey: "PUBLIC_SDK_KEY")
.with(customerUserId: "YOUR_USER_ID", withAppAccountToken: UUID())
Adapty.activate(with: configurationBuilder.build()) { error in
// handle the error
}
// Or when identifying a user:
Adapty.identify("YOUR_USER_ID", withAppAccountToken: UUID()) { error in
if let error {
// handle the error
}
}
You can then login the user using .identify()
method.
Set appAccountToken on iOS
The appAccountToken
is a UUID that helps Apple's StoreKit 2 identify users across app installations and devices.
Starting from the Adapty iOS SDK 3.10.2, you can pass the appAccountToken
when configuring the SDK or when identifying a user:
- Swift
- Swift-Callback
// During configuration:
let configurationBuilder =
AdaptyConfiguration
.builder(withAPIKey: "PUBLIC_SDK_KEY")
.with(customerUserId: "YOUR_USER_ID", withAppAccountToken: UUID())
do {
try await Adapty.activate(with: configurationBuilder.build())
} catch {
// handle the error
}
// Or when identifying a user:
do {
try await Adapty.identify("YOUR_USER_ID", withAppAccountToken: UUID())
} catch {
// handle the error
}
// During configuration:
let configurationBuilder =
AdaptyConfiguration
.builder(withAPIKey: "PUBLIC_SDK_KEY")
.with(customerUserId: "YOUR_USER_ID", withAppAccountToken: UUID())
Adapty.activate(with: configurationBuilder.build()) { error in
// handle the error
}
// Or when identifying a user:
Adapty.identify("YOUR_USER_ID", withAppAccountToken: UUID()) { error in
if let error {
// handle the error
}
}