简体   繁体   English

离子框架 - 检测互联网连接

[英]Ionic framework - detect internet connection

I am developing simple application using Ionic framework (and AngularJs) that fetches json data from my webpage. 我正在使用Ionic框架(和AngularJs)开发简单的应用程序,该框架从我的网页中获取json数据。 How can I detect is there "internet connection" and display message to user: "Connect to internet" if not. 如何检测是否存在“互联网连接”并向用户显示消息:“如果没有,则连接到互联网”。

EDIT 编辑

Can I use cordova API for that ? 我可以使用cordova API吗?

Cordova provides org.apache.cordova.network-information plugin. Cordova提供org.apache.cordova.network-information插件。

See documentation HERE 请参阅此处的文档

This plugin provides an implementation of an old version of the Network Information API. 此插件提供旧版Network Information API的实现。 It provides information about the device's cellular and wifi connection, and whether the device has an internet connection. 它提供有关设备的蜂窝和wifi连接以及设备是否具有互联网连接的信息。

If I am not mistaken, this plugin only detects whether the Wi-Fi or Cellular networking is enabled on the device. 如果我没有弄错的话,这个插件只会检测设备上是否启用了Wi-Fi或Cellular网络。 This does not always mean that the application can actually reach your remote server, if you are connected to the WiFi network without internet connection. 如果您在没有互联网连接的情况下连接到WiFi网络,这并不总是意味着应用程序可以实际到达您的远程服务器。 Therefore, the only solution I have found to ensure that the application can reach your remote server is to continuously ping the server. 因此,我发现确保应用程序可以访问远程服务器的唯一解决方案是持续ping服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM