如何在使用Firebase iOS SDK时检测用户是否在线

如何在使用Firebase iOS SDK时检测用户是否在线,第1张

概述在发送消息(即在Firebase对象上调用setValue)之前,是否有建议的方法来确定用户是在线还是离线? 例如: [firebase setValue:someValue withCompletionBlock:^(NSError *error, Firebase *ref) { // This block is ONLY executed if the write actually 在发送消息(即在Firebase对象上调用setValue)之前,是否有建议的方法来确定用户是在线还是离线?

例如:

[firebase setValue:someValue withCompletionBlock:^(NSError *error,Firebase *ref) {    // This block is ONLY executed if the write actually completes. But what if the user was offline when this was attempted?    // It would be nicer if the block is *always* executed,and error tells us if the write Failed due to network issues.}];

我们在iOS应用程序中需要这个,因为如果用户进入隧道,用户可能会失去连接.如果Firebase没有提供内置的方法,我们只需要监控iOS的Reachability API.

解决方法 他们有一段专门讨论这个 here.的文档

基本上观察.info / connected ref

Firebase* connectedRef = [[Firebase alloc] initWithUrl:@"https://SampleChat.firebaseIO-demo.com/.info/connected"];[connectedRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot,Nsstring *prevname) {    if([snapshot.value boolValue]) {        // connection established (or I've reconnected after a loss of connection)    }    else {        // disconnected    }}];
总结

以上是内存溢出为你收集整理的如何在使用Firebase iOS SDK时检测用户是否在线全部内容,希望文章能够帮你解决如何在使用Firebase iOS SDK时检测用户是否在线所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1076043.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存