client.addDevice(
Device(
token = "push-provider-token",
pushProvider = PushProvider.FIREBASE,
providerName = "provider_name", // Optional, if adding to multi-bundle named provider
)
).enqueue { result ->
if (result.isSuccess) {
// Device was successfully registered
} else {
// Handle result.error()
}
}Registering Push Devices
Once your app has enabled the push notifications, you can use the APIs to register user devices such as iPhones and Android phones.
Each chat user has a limit of 25 unique devices. Once this limit is reached, the oldest device will be removed and replaced by the new device.
Device Parameters
| name | type | description | default | optional |
|---|---|---|---|---|
| user_id | string | The user ID for this device | - | |
| id | string | The device ID. | - | |
| push_provider | string | The push provider for this device. Either APN, Firebase, Huawei, or Xiaomi. | - | |
| disabled | boolean | Set if the device is disabled | - | ✓ |
| disabled_reason | string | Explanation if the device is disabled | - | ✓ |
| push_provider_name | string | The push provider name for this device if a multi-bundle configuration is added. | - | ✓ |
Register a Device
Registering a device associates it with a user and tells the push provider to send new message notifications to the device.
Register the user's device for remote push notifications once your user is successfully connected to Chat.
Multi-bundle configurations require that you specify a push_provider_name when registering a device that corresponds to the name of the push configuration that you've set up in the dashboard or via the API.
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// Note: If you leverage mutli-bundle configuration, please provide providerName - name of your configuration
chatClient.currentUserController().addDevice(.apn(token: deviceToken)) { error in
if let error = error {
print("Error adding device token.", error)
}
}
}Unregister a Device
Unregistering a device removes the device from the user and stops further new message notifications.
let currentUserController = chatClient.currentUserController()
guard let device = currentUserController.currentUser?.currentDevice else {
// No device to remove
}
currentUserController.removeDevice(id: device.id) { error in
if let error = error {
print("Error removing the device", error)
}
}List Devices
Provides a list of all devices associated with a user.
let currentUserController = chatClient.currentUserController()
currentUserController.synchronizeDevices { error in
guard error == nil else {
print("Error getting the list of devices")
return
}
let devices = currentUserController.currentUser?.devices
}