Assertion failed: You can only track your presence after subscribing to the channel. Did you forget to call `channel.subscribe()`?
Bug report
- [X] I confirm this is a bug with Supabase, not with my own application.
- [X] I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
I've noticed that an increase of assert crash Assertion failed: You can only track your presence after subscribing to the channel. Did you forget to call channel.subscribe()? even though I'm calling subscribe()
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Launch app
- Ensure presence is configured for when the user launches the app
Expected behavior
Crash does not occur
Screenshots
System information
SupabaseSDK 2.20.5
Additional context
My function
func setUserPresence() async {
var isTracked = false
let deviceId = UIDevice.current.identifierForVendor?.uuidString ?? "unknown-user"
let realtime = supaBaseClient.realtimeV2
let userPresence = supaBaseClient.channel("user_presence")
let presenceStream = userPresence.presenceChange()
await userPresence.subscribe()
for await presence in presenceStream {
// Handle joins
if !presence.joins.isEmpty && !isTracked {
await userPresence.track(
state: [
"user": .string(deviceId),
"onlineAt": .double(Date().timeIntervalSince1970)
]
)
isTracked = true // Update the state
}
// Handle leaves
if !presence.leaves.isEmpty && isTracked {
await userPresence.untrack()
isTracked = false // Update the state
}
}
}
Hi @arbyruns,
Did you notice this assertion increases after an update? Which version were you before if that is the case? Also, please make sure nothing has changed in your code that could lead to this increase.
Thanks
Did you notice this assertion increases after an update?
I can't say for sure since this is a new implementation. I was also hitting this with the Android SDK. I've since removed the code from my app because it was chewing through my monthly allotment.