简体   繁体   English

离子模拟ios仅适用于--livereload

[英]Ionic emulate ios only works with --livereload

I have a simple ionic app that I'm building and when I test with ionic serve --lab , everything looks great, however, when I try to emulate on the simulators with ionic emulate ios or ionic emulate android , the app doesn't load (seems like all the JS isn't coming through). 我正在构建一个简单的ionic应用程序,当我用ionic serve --lab测试时,一切看起来都不错,但是,当我尝试使用ionic serve --lab ionic emulate iosionic emulate android在模拟器上进行仿真时,该应用程序没有加载(似乎所有JS都无法通过)。 I am able to attach the debugger and there aren't any console errors. 我能够附加调试器,并且没有任何控制台错误。

But, when I do try and run the app with ionic emulate ios --livereload everything seems to work fine. 但是,当我尝试使用ionic emulate ios --livereload运行该应用程序时,一切似乎都可以正常工作。

I tried another sample app from scratch to rule out my machine env and it worked fine. 我从头开始尝试了另一个示例应用程序,以排除我的机器环境,并且工作正常。

Any ideas on how I can get the emulate to work without --livereload? 关于如何在没有--livereload的情况下如何运行仿真的任何想法?

I had the same issue today. 我今天有同样的问题。 I resolved it by removing certain angular dependencies that weren't being detected by the ios build. 我通过删除ios构建未检测到的某些角度依赖性解决了该问题。 Check your jslint for any warnings that may provide more information about which dependencies may be injected incorrectly or missing. 检查您的jslint是否有任何警告,这些警告可能会提供有关哪些依赖项可能被错误注入或丢失的更多信息。

See this comment on the Ionic forums for further info. 有关更多信息,请在Ionic论坛上查看此评论

In my case the white screen of death was caused by bad references to bower components. 在我的案例中,白屏死机是由于对凉亭组件的错误引用引起的。

For our build process, the relative location of bower components is different is the "source" compared to when the app has been packaged to "www" (bower components are copied to the root directory). 在我们的构建过程中,与应用程序打包到“ www”(bower组件被复制到根目录)相比,bower组件的相对位置是“源”。

The following reference works when the app is served (if you hover over the links in Chrome inspector, the ".." is removed), but don't work when launched on a device/emulator: 提供服务时,以下参考有效(如果将鼠标悬停在Chrome检查器中的链接上,则“ ..”将被删除),但在设备/仿真器上启动时则无效:

<script src="../bower_components/angular/angular.js"></script>

Live reload works because the application is not being served from the device's file system . 实时重新加载有效,因为未从设备的文件系统提供应用程序 Instead Ionic is serving it from the host machine and presumably the bad relative path ("..") is silently ignored as it is when tested in the browser. 取而代之的是,Ionic从主机上为它提供服务,并且大概是错误的相对路径(“ ..”)在浏览器中进行测试时被默默地忽略了。

Fixing the paths as follows resolved in the problem: 解决以下问题的路径已解决:

<script src="bower_components/angular/angular.js"></script>

The outstanding question is why no apparent errors are thrown by any component of the application. 悬而未决的问题是,为什么应用程序的任何组件都不会引发明显的错误。

1. Find Errors 1.查找错误

Start your emulation like this 这样开始仿真

 $ ionic emulate android -l -c

This will emulate with livereload and log to your console . 这将模拟livereload并登录到控制台

Now you should see whats causing the error, logged in the terminal. 现在,您应该查看导致错误的原因,并在终端上登录。

2. Missing Cordova Whitelist Plugin? 2.缺少Cordova白名单插件?

Often there's the missing Cordova Whitelist Plugin . 通常,缺少缺少的Cordova Whitelist插件 As you can read here simply do the following steps to get this plugn to work. 如您在这里所读只需执行以下步骤即可使该插件正常工作。

$ ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git

if not already added. 如果尚未添加。

open your config.xml inside your project root and add this line inside the <widget> tag. 在项目根目录下打开config.xml并将此行添加到<widget>标记内。

<allow-navigation href="*" />

就我而言,此问题是由于index.html中包含<base href="/">而引起的,这不会阻止Ionic(通过--livereload)查找本地托管的文件,但完全阻止了Ionic在其中查找文件。捆绑的iOS或Android应用。

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

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