2021 Audio & Video
WWDC21 · 25 min · Audio & Video
Build custom experiences with Group Activities
Go beyond basic streaming and interaction and discover how you can build advanced SharePlay experiences using the full power of the Group Activities framework. We’ll show you how to adapt a simple drawing app into a real-time shared canvas, explore APIs like GroupSessionMessenger — which helps send and receive custom messages between participants in the group — and learn how to put the finishing touches on a custom SharePlay experience.
Watch at developer.apple.com ↗Code shown on screen · 2 snippets
Configuring your application’s activity
struct DrawTogether: GroupActivity {
var metadata: GroupActivityMetadata {
var metadata = GroupActivityMetadata()
metadata.title = NSLocalizedString("Draw Together",
comment: "Title of group activity")
metadata.type = .generic
return metadata
}
} Define, Receive and Send messages
let messenger = GroupSessionMessenger(session: groupSession)
// 1. Define
struct UpsertStrokeMessage: Codable {
let id: UUID
let color: Color
let point: CGPoint
}
// 2. Receive
for await (message, context) in messenger.messages(of: UpsertStrokeMessage.self) {
// Handle message
}
// 3. Send
do {
try await messenger.send(UpsertStrokeMessage(id: stroke.id, color: .red, point: point))
} catch {
// Handle error
} Resources
Related sessions
-
25 min -
17 min -
9 min -
38 min