2017-06-01 66 views
0

我已经安装cordova-plugin-network-information使用CLI进行离子项目。我可以看到该插件在android.json文件在项目的根文件夹中,也在cordova_plugin.js在android平台文件夹中。科尔多瓦插件网络信息未按预期工作

cordova_plugin.js:

{ 
     "id": "cordova-plugin-network-information.network", 
     "file": "plugins/cordova-plugin-network-information/www/network.js", 
     "pluginId": "cordova-plugin-network-information", 
     "clobbers": [ 
      "navigator.connection", 
      "navigator.network.connection" 
     ] 
    } 

android.json:

"cordova-plugin-network-information": { 
      "PACKAGE_NAME": "com.ionicframework.fts1243245" 
     } 

我打过电话window.Connection离子作为准备:

$ionicPlatform.ready(function() { 
     if(window.Connection){ 
      if(navigator.connection.type == Connection.NONE){ 
       $ionicPopup.confirm({ 
        title:"Internet Disconnected", 
        content:"The internet is disconnected on your device." 
       }) 
       .then(function(result){ 
        if(!result){ 
        ionic.Platform.exitApp(); 
        }else{ 
         ionic.Platform.exitApp(); 
        } 
       }); 
      } 
     } 
} 

但是,窗口。连接返回undefined

任何人都可以请让我知道出了什么问题吗?

回答

0

This answer

这都说明$ ionicPlatform.ready可以科尔多瓦的onDeviceReady(),这将完全解释你所看到的之前运行 - 这个答案提供了一些选项,以减轻这一点。我认为最简单的办法就是运行onDeviceReady()中的退出代码(如果您可以安全地假设它会在$ ionicPlatform.ready之后触发)。

如果你觉得不痛快假设它则:

  1. 移动所有你在$ ionicPlatform.ready运行到一个独立的功能筹备代码。在$ ionicPlatform.ready()和onDeviceReady(
  2. 组标志),并在每年年底检查,看是否都已经设置并运行准备功能
+0

感谢您的回复,我会检查并更新你,Actully我用我以前的应用程序相同的代码一切工作正常,我以前没有使用deviceRedy() – Selva