使用Firebase测试Internet连接 [英] Testing Internet Connection With Firebase

查看:102
本文介绍了使用Firebase测试Internet连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处

但是我发现侦听器失去了连接"或按照理想状态停止工作.起初它可以正常工作,即如果我打开/关闭wifi/sim数据,那么它可以正确显示天气,无论我在线还是离线但是过了一段时间(大约20秒钟左右)后,它停止工作,即使我连接到Internet也会始终显示未连接状态.如果我打开和关闭网络连接也不会改变.重新启动我的应用程序,但过一会儿它又停止工作了.

but what i found is that the listener "looses connection" or stops working as it should ideally.At first it works fine i.e if i turn on/off my wifi/sim data then it shows correctly weather i am online or offline but then after some time (around 20 seconds or so) it stops working and always gives state as not connected even if i am connected to internet.It doesn't change if i toggle my net connection on and off.It works fine if i restart my app but after some time it stops working again.

我尝试搜索答案,但找不到任何解决方案,有人建议侦听器在一段时间后关闭连接并需要重新初始化,但这是否违反了它的目的? 我也尝试使用onDiscoonect(),但找不到重新启动它的方法.

I tried searching for answers but i could not find any solution, Someone suggested that the listener closes the connection after sometime and needs to be reinitialized.But doesn't that defeat the purpose for which it was made for? I also tried using onDiscoonect() but couldn't find a way to restart it.

一种解决方案可能是在一段时间后使用处理程序一次又一次地重新初始化它,但这不是它应该如何工作的.

One solution might be to reinitialize it again and again after a set period of time using handler,but that is not how its supposed to work.

有更好的解决方案吗?

推荐答案

.info/connected侦听器报告Firebase数据库连接(即WebSocket)的状态.它不会报告您的Internet连接状态.

The .info/connected listener reports the state of the Firebase database connection, which is a WebSocket. It does not report the state of your Internet connection.

Firebase自动管理其WebSocket连接.如果没有活动的侦听器或挂起的写入,则连接将关闭.请参阅与此相关问题.

Firebase auto-manages its WebSocket connection. If there are no active listeners or pending writes, the connection is closed. See this related question.

这篇关于使用Firebase测试Internet连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆