sessions()
Returns the sessions for this activity as an asynchronous sequence.
Declaration
static func sessions() -> Self.SessionsReturn Value
An AsyncSequence type that contains the GroupSession objects for this activity.
Discussion
Use this method to retrieve new sessions for the current activity. The method returns a sequence that may contain some or none of its values when you access it. The system adds an element to the sequence when the participant joins a new activity. It doesn’t update the sequence when properties of an active session change. For example, it doesn’t update the sequence when the state of the session changes.
Use a for-in loop to iterate over the values in the sequence. Preface your loop with await to receive each value asynchronously as it becomes available. To avoid blocking your code, perform the iteration from an asynchronous task in your app. The following example shows a typical way to call this method asynchronously:
async {
for await newSession in MyActivity.sessions() {
// Start a new activity.
}
}When a new session arrives, use it to prepare your app’s UI for the new activity.