例如:
[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时检测用户是否在线所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)