Platform Surface
| Platform | Repository | Main APIs |
|---|---|---|
| iOS | AmityUserPresenceRepository() | getUserPresence(userIds:), syncUserPresence(id:viewId:), getSyncingUserPresence(), getOnlineUsersCount(), getOnlineUsersSnapshot() |
| Android | AmityCoreClient.newUserPresenceRepository() | getUserPresence(userIds), syncUserPresence(userId, viewId), getSyncingUserPresence(), getOnlineUsersCount(), getOnlineUsersSnapshot() |
| TypeScript | Not available | Not available |
| Flutter | Not available | Not available |
Parameters
| Operation | Parameter | Required | Description |
|---|---|---|---|
getUserPresence | userIds | Yes | User IDs to read. iOS documents a maximum of 220 IDs per call. Keep Android calls bounded for the same reason. |
syncUserPresence | id / userId | Yes | User ID whose presence should be refreshed periodically while visible. |
syncUserPresence | viewId | No | Stable view identifier. Defaults to amity-global; use a custom value when the same user can appear in multiple visible UI locations. |
unsyncUserPresence | id / userId | Yes | User ID to remove from syncing. |
unsyncUserPresence | viewId | No | Must match the viewId used when syncing if you passed a custom value. |
unsyncAllUserPresence | None | No | Stops syncing all user presence tracked by the SDK presence engine. |
getSyncingUserPresence | None | No | Returns iOS AnyPublisher<[AmityUserPresence], Error> or Android Flowable<List<AmityUserPresence>>. |
getOnlineUsersCount | None | No | Returns the current count of online users in the network. |
getOnlineUsersSnapshot | None | No | Returns a point-in-time, paginated snapshot of online users. iOS and Android load users 20 at a time. |
User Presence Object
| Field | iOS | Android | Description |
|---|---|---|---|
| User ID | presence.userId | presence.getUserId() | The user represented by this presence record. |
| Last heartbeat | presence.lastHeartbeat | presence.getLastHeartbeat() | Last heartbeat timestamp, when available. |
| Online state | presence.isOnline | presence.isOnline() | true when the last heartbeat is within the SDK online threshold. |
The SDK limits active presence syncing to 20 user IDs at a time. Unsync users when their row, card, or profile preview is no longer visible.
Read User Presence
Fetch presence for known users as a one-shot read.Sync User Presence
Sync user presence while users are visible, then unsync them when the UI no longer needs updates.Read Online Users Count And Snapshot
Use the count for a network-wide online total. Use the snapshot when you need actual user objects at the time of the query.Best Practices
Start the current user's heartbeat
Start the current user's heartbeat
Other users can only see the current user as online if the app enables presence and starts the current user’s heartbeat. See Heartbeat Sync.
Sync only visible users
Sync only visible users
Bind
syncUserPresence to visible UI rows, cells, or cards. Call unsyncUserPresence during cell reuse, unmount, or screen dismissal.Use snapshots for discovery, not live badges
Use snapshots for discovery, not live badges
getOnlineUsersSnapshot is a point-in-time read. For live online badges, sync specific visible users instead.Related Topics
Channel Presence
Show whether any other member of a conversation channel is online.
Heartbeat Sync
Mark the current user as online with the SDK heartbeat.