Register a device
A device must be registered before an Amazon Connect journey can deliver a notification to it. Registering stores the device's push token against the current user's profile identity, so your backend knows where to send messages.
Register with the APNs device token
Obtain the token from your application delegate's remote notification callback and pass it to registerDevice:
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let token = deviceToken.map { String(format: "%02x", $0) }.joined() Task { try await client.registerDevice(token: token) }}Requesting notification permission with UNUserNotificationCenter and calling registerForRemoteNotifications() remain your application's responsibility; the client only registers the token with your backend.
The token is the only value you provide
The library resolves the remaining device fields for you:
| Field | Source |
|---|---|
deviceId | A stable identifier the library generates and persists per installation, shared with other Amplify libraries. |
platform | The current operating system. |
appVersion | The host application's CFBundleShortVersionString, if present. |
channelType | APNS_SANDBOX for debug builds, APNS otherwise. |
Registration is an idempotent operation keyed on deviceId, so calling registerDevice again with a new token updates the existing record rather than creating a second one.
The device belongs to the current identity
The registered device is stored against the principalId that your backend derives from the signed request, so a device always belongs to the identity that registered it. Your application never sends a user identifier, and one user cannot register a device against another user's profile.
Because the identity comes from Amazon Cognito identity pool credentials, registration works for guest users as well as signed-in users.
When to call registerDevice
Call registerDevice in these situations:
- After the user grants notification permission and the platform issues a push token.
- Whenever the platform rotates the token.
- After a user signs in, to move the device registration from the guest identity to the authenticated one. See Guest and authenticated users.
You do not need to call registerDevice on every application start. The registration persists until it is removed or the token changes.
Handle errors
registerDevice throws a ConnectError when the token is invalid or the request cannot complete:
do { try await client.registerDevice(token: token)} catch { print("Failed to register device: \(error)")}Next steps
- Remove a device: de-register a device before signing a user out.