Devices

Last Edit: Sep 22 2020

Once your app has push enabled, 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. -
provider string The push provider for this device. Either APN or firebase. -

Register a Device


await client.addDevice(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    'apn', 
    '42'
)
                    

client.add_device(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    'apn', 
    '42'
)
                    

client.add_device(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    'apn', 
    '42'
)
                    

client.addDevice(deviceToken, new CompletableCallback() { ... });
                    

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Client.shared.addDevice(deviceToken: deviceToken)
    // or
    Client.shared.addDevice(deviceToken: deviceToken) { (result) in /* Handle result */ }
}
                    

stream chat:push:device:add \
    --device_id '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207'
    --user_id '42'
    --provider 'apn'
                    

$add = $client->addDevice(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    'apn', 
    'elon'
);
                    

// register the device with APN (Apple only)
await client.addDevice("device-token", "apn");
        
// register the device with Firebase (Android only)
await client.addDevice("device-token", "firebase");
                    

_ = client.AddDevice(&Device{
	ID:           "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207",
	UserID:       "elon",
	PushProvider: PushProviderAPNS,
})
                    

FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener {
    val token = it.token
    client.addDevice(token).enqueue { addDeviceResult ->
        println(addDeviceResult)
    }
}
                    

Unregister a Device


await client.removeDevice(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    '42'
)
                    

client.delete_device(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    '42'
)
                    

client.delete_device(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    '42'
)
                    

client.removeDevice(deviceToken, new CompletableCallback() { ... });
                    

let deviceId = User.current.devices.last!.id
Client.shared.removeDevice(deviceId: deviceId)
                    

stream chat:push:device:delete \
    --device_id '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207'
    --user_id '42'
                    

$delete = $client->deleteDevice(
    '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207', 
    'elon'
);
                    

await client.removeDevice("device-token");
                    

deviceID := "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207"
userID := "elon"
_ = client.DeleteDevice(userID, deviceID)
                    

FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener {
    val token = it.token
    client.deleteDevice(token).enqueue { deleteDeviceResult ->
        println(deleteDeviceResult)
    }
}