如果我关闭 wifi,则无法使 ionic 应用程序工作(在开发过程中) [英] Can't get ionic app to work (while developing) if I turn off wifi

查看:35
本文介绍了如果我关闭 wifi,则无法使 ionic 应用程序工作(在开发过程中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在开发时我关闭了 wifi,然后离子应用程序在 android 设备/模拟器中不起作用.

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

但是当我使用已发布并签名的 android 应用程序的 apk 文件关闭 wifi 时,它工作得很好.

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();
        }
      }

但是由于如果我关闭 wifi,该应用程序不会在模拟器或设备上运行,因此我无法测试代码是否工作而无需构建非常耗时的发布 apk.即使我关闭了 wifi,我怎样才能让它工作?

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?

我收到如下错误消息:

推荐答案

当您使用 ionic run android -l -c 运行应用程序时,所有数据和资源都将从您的计算机通过网络提供.事实上,在这种情况下,它在移动设备上的运行方式与您在带有 ionic serve 的计算机浏览器上运行的方式相同.因此,当您关闭移动互联网时,将无法从计算机提供服务,因为网络是提供页面服务的渠道.但是ionic run android将所有的应用源都打包在移动端,资源来自file:///android_asset/www/.

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/.

ionic run -l -c 的真正目的:l 代表肝加载,只要源代码发生变化,它就会在移动设备上不断刷新您的应用程序.c 代表控制台,应用程序控制台日志显示在您启动应用程序的命令行中.它可以帮助 ionic 开发人员进行测试,因为他们不必一次又一次地安装应用程序.但是请记住将手机连接到计算机,并且两者都应该在同一个互联网网络上.

注意:有时cordova plugins(如相机等)在这种环境中表现得很奇怪.因此,在检查插件相关功能时,最好不要使用 -l -c.

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.

这篇关于如果我关闭 wifi,则无法使 ionic 应用程序工作(在开发过程中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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