ios - Firebase crashes with 'listen() called twice for the same query' error -
i trying follow advice , remove listener when needed , register listener when needed. in uiviewcontroller.viewdidappear have following:
let chatref = messagesref.childbyappendingpath(chat.objectid!) var query = chatref.queryorderedbychild("createdat") if let since = since { query = query.querystartingatvalue(since.timeintervalsince1970 * 1000) } let handle = query.observeeventtype(feventtype.childadded, withblock: completion, withcancelblock: { (error: nserror!) -> void in println("error listening new chat messages: \(error)") });
in uiviewcontroller.viewwilldisappear() have
let chatref = messagesref.childbyappendingpath(chat.objectid!) if chatref != nil { chatref.removeallobservers() }
but program crashes every time viewcontroller entered second time (going view controller, navigate away, come back) following error:
*** assertion failure in -[fpersistentconnection listen:tagid:hashfn:oncomplete:], /users/mtse/dev/firebase/firebase-client-objc/firebase/firebase/core/fpersistentconnection.m:127 *** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'listen() called twice same query'
the program runs fine if don't remove observers , call observeeventtype once in viewdidload
instead of viewdidappear.
the program runs fine if remove observer add if don't queryorderedbychild
, querystartingatvalue
.
so doing wrong here?
disclaimer: work firebase
listeners in firebase specific path or query register them on. calling removeallobservers()
removes observers, only path.
so in viewwilldisappear()
need remove listeners query, instead of ref.
query.removeallobservers()
we made more explicit in our documentation , looking @ ways make api more intuitive.
update (20150724)
it turns out calling removeallobservers()
on ffirebase
should remove observers on queries on same location too. not remove observers @ child()
locations, should have worked in case.
we investigating going wrong, seems have hit bug in our ios sdk. once find it, we'll release fixed version. in meantime above serves (and continue serve) valid workaround.
Comments
Post a Comment