-
Notifications
You must be signed in to change notification settings - Fork 29
Presence Status
Presence Status API provides real-time status updates about contacts which include predefined states, custom messages, and state-specific expiration and last active times. The usage of the API revolves around starting and stopping to watch the presence status of specific contacts.
The related APIs can be accessed through PersonClient.swift
. This functionality is available starting from SDK version 3.10.0.
-
PresenceHandle
-
handle: NSNumber: Get the unique handle identifier.
PresenceHandle
object (returned whilestartWatchingPresences
) will have distinct handle identifier for each contactID. - contactId: String: Retrieve the contact ID.
-
isValid: Bool: Check if the handle is valid. For invalid contact Ids or bot contact Ids this will return
false
.
-
handle: NSNumber: Get the unique handle identifier.
-
Presence
- contactId: String: Obtain the contact's ID for this presence status.
- status: PresenceStatus: Get the current presence status.
- customStatus: String: Retrieve any custom status message set by user.
- lastActiveTime: Long: Obtain the last active UTC time in milliseconds.
- expiresTime: Date: Get the expiry UTC time in milliseconds for statuses like DND, OutOfOffice, etc.
- Unknown
- Pending
- Active
- Inactive
- Dnd (Do Not Disturb)
- Quiet
- Busy
- OutOfOffice
- Call
- Meeting
- Presenting
- CalendarItem
To start watching presence status updates for a list of contact IDs, use the webex.people.startWatchingPresences()
API.
let contactIds = ["ContactId1", "ContactId2"]
let presenceHandles = webex.people.startWatchingPresences(contactIds: contactIds, completionHandler: { presence in
// Handle presence updates
print("Updated presence for \(presence.contactId): \(presence.status)")
}
When no longer needed, use webex.people.stopWatchingPresences()
to stop receiving updates for a list of presence handles.
webex.people.stopWatchingPresences(presenceHandles: presenceHandles)
Upon receiving a presence update, utilize the Presence struct to manage and display the obtained information. Ensure to respect the expiresTime
for statuses like DND, OutOfOffice, etc., and use lastActiveTime
to display how long a user has been inactive.
Example:
let presenceHandles = webex.people.startWatchingPresences(contactIds: contactIds, completionHandler: { presence in
// Handle presence updates
print("Contact: \(presence.contactId)")
print("Status: \(presence.status}")
print("Custom Message: \(customStatus)")
if presence.status == PresenceStatus.Inactive {
print("Last active: (\presence.lastActiveTime)ms ago")
}
if [PresenceStatus.OutOfOffice, PresenceStatus.Dnd, PresenceStatus.Quiet].contains(presence.status)
{
print("Status expires in: \(presence.expiresTime)ms")
}
}