Best practice on Set Method when switch from online to offline

29 views
Skip to first unread message

Cyril Ferey

unread,
Sep 14, 2017, 10:25:14 AM9/14/17
to Firebase Google Group
 I have a question about `set` method in Firebase ios SDK. To write something in our datastore, we use:

open func setValue(_ value: Any?, andPriority priority: Any?, withCompletionBlock block: @escaping (Error?, DatabaseReference) -> Swift.Void)


When the app is offline, we saw that the completion block is not called and only when we go back online it's okay.
Our app implementations wait for this callback to continue the flow, but we are blocked if the app turns offline. (We wait this callback to be notified of any kind of error)

Do we need to ignore this callback and we won't have any error (because we are offline) ?
 because if we don't ignore it, that means we silent a possible error emitted by the sdk.

What's is the best practice ?

Kato Richardson

unread,
Sep 14, 2017, 2:04:45 PM9/14/17
to Firebase Google Group
Cyril, looks like the same thing you posted in chat earlier. This is likely an XY problem. Describing the use case here will be crucial to giving you any useful advice.

Generally speaking, the best practice is to work offline the same as if you're online and not depend on the success callback. Your local app will still get added/updated/removed events and you should process those normally rather than depending on the write callbacks. In other words, use it as a one-directional event stream rather than a multi-path CRUD tool. 

If you're doing some sort of op that depends on remote state, you'll likely need to disallow that while offline, obviously. Hard to be more specific without knowing the end goal.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/b4a3411b-8bf8-424f-a4e3-f9445da34e70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages