Can't get ionic app to work (while developing) if I turn off wifi

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 04:42:06

问题


So while developing I turn off the wifi and then the ionic app doesn't work in android device/emulator.

But when I turn off wifi with the released and signed apk file for android app works just fine.

The thing is I need my app to do something when internet connection is off to do something:

   if(window.Connection) {
        if(navigator.connection.type == Connection.NONE) {
            //doSomething();
        }
      }

But since the app doesn't run on emulator nor device if I turn off wifi there is no way I can test if code worked without having to build a release apk which is very time consuming. How can I make it work even if I turn wifi off?

I get an error message like this:


回答1:


When you run application with ionic run android -l -c then all data and resources are being served from your computer through network. In fact in that case it works on mobile in same way you run on computer browser with ionic serve. So when you turn off mobile internet then it is unable to serve from computer, as network was channel to serve pages. But ionic run android packages all aplication sources in mobile and resources are served from file:///android_asset/www/.

Real Purpose of ionic run -l -c : l stands for liverload, which keeps on refreshing your application in mobile whenever there is change in source. c stands for console, application console logs are shown in your command line from where you initiated application. It helps ionic developers for testing, as they do not have to install application again and again. But remember keep your phone connected to computer and both should be on same internet network.

NOTE: Sometimes cordova plugins like camera etc behave strange in this enviroment. So better use without -l -c while checking plugins related functionalities.




回答2:


just solved the issue. I was trying to run the app with ionic run android -l -cso now I run it with ionic run android and off course that doesn't need livereload -l and now app works just fine



来源:https://stackoverflow.com/questions/32530388/cant-get-ionic-app-to-work-while-developing-if-i-turn-off-wifi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!