iOS/Swift
Devices
Confused about "Devices"?
Let us know how we can improve our documentation:
LAST EDIT Mar 05 2021
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
Copied!Confused about "Device Parameters"?
Let us know how we can improve our documentation:
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 or firebase. | - | |
disabled | boolean | Set if device is disabled | - | ✓ |
disabled_reason | string | Explanation if device is disabled | - | ✓ |
Register a Device
Copied!Confused about "Register a Device"?
Let us know how we can improve our documentation:
1
2
3
4
5
await client.addDevice(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'apn',
'42'
)
1
2
3
4
5
client.add_device(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'apn',
'42'
)
1
2
3
4
5
client.add_device(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'apn',
'42'
)
1
2
3
4
5
6
7
client.addDevice("firebase-token").enqueue(result -> {
if (result.isSuccess()) {
// Device was successfully registered
} else {
// Handle result.error()
}
});
1
2
3
4
5
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Client.shared.addDevice(deviceToken: deviceToken)
// or
Client.shared.addDevice(deviceToken: deviceToken) { (result) in /* Handle result */ }
}
1
2
3
4
stream chat:push:device:add \
--device_id '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207'
--user_id '42'
--provider 'apn'
1
2
3
4
5
$add = $client->addDevice(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'apn',
'elon'
);
1
2
3
4
5
// 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");
1
2
3
4
5
_ = client.AddDevice(&Device{
ID: "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207",
UserID: "elon",
PushProvider: PushProviderAPNS,
})
1
2
3
4
5
6
7
client.addDevice("firebase-token").enqueue { result ->
if (result.isSuccess) {
// Device was successfully registered
} else {
// Handle result.error()
}
}
Unregister a Device
Copied!Confused about "Unregister a Device"?
Let us know how we can improve our documentation:
1
2
3
4
await client.removeDevice(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'42'
)
1
2
3
4
client.delete_device(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'42'
)
1
2
3
4
client.delete_device(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'42'
)
1
2
3
4
5
6
7
client.deleteDevice("firebase-token").enqueue(result -> {
if (result.isSuccess()) {
// Device was successfully unregistered
} else {
// Handle result.error()
}
});
1
2
let deviceId = User.current.devices.last!.id
Client.shared.removeDevice(deviceId: deviceId)
1
2
3
stream chat:push:device:delete \
--device_id '2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207'
--user_id '42'
1
2
3
4
$delete = $client->deleteDevice(
'2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207',
'elon'
);
1
await client.removeDevice("device-token");
1
2
3
deviceID := "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207"
userID := "elon"
_ = client.DeleteDevice(userID, deviceID)
1
2
3
4
5
6
7
client.deleteDevice("firebase-token").enqueue { result ->
if (result.isSuccess) {
// Device was successfully unregistered
} else {
// Handle result.error()
}
}
List Devices
Copied!Confused about "List Devices"?
Let us know how we can improve our documentation:
1
await client.getDevices(user_id)
1
client.get_devices(user_id)
1
client.get_devices(user_id)
1
$client->getDevices($userID)
1
client.GetDevices(userID)
1
stream chat:push:device:get --user_id '42'
1
2
3
4
5
6
7
client.getDevices().enqueue { result ->
if (result.isSuccess) {
val devices: List<Device> = result.data()
} else {
// Handle result.error()
}
}
1
2
3
4
5
6
7
client.getDevices().enqueue(result -> {
if (result.isSuccess()) {
List<Device> devices = result.data();
} else {
// Handle result.error()
}
});