javascript - 将 ionic 应用程序中的域列入白名单

标签 javascript android angularjs ionic-framework

我正在浏览

中的 ionic 教程
http://ccoenraets.github.io/ionic-tutorial/build-ionic-project.html

并在浏览器上运行应用程序

ionic serve

在android中使用

ionic emulate android 

当我按照教程中的说明运行应用程序时,它在我的 Chrome 浏览器上运行良好,但当我尝试在模拟器上运行时,我看不到任何数据,它只是带有菜单的空屏幕。我怀疑这是 whilelist 的问题并添加了

  <allow-navigation href="*" />

到我的/config.xml 文件,但它仍然不起作用,我当前的 config.xml 文件是

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.conference472350" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>conference</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">
      Ionic Framework Team
    </author>
  <content src="index.html"/>
  <access origin="*" />
  <allow-intent href="*" />
  <allow-navigation href="*" />
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="SplashScreenDelay" value="3000"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  <platform name="android">
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
  </platform>
</widget>

我正在 chrome devtools 中调试应用程序,这是我在应用程序控制台中遇到的错误

Failed to load resource: net::ERR_CONNECTION_REFUSED

enter image description here

最佳答案

有趣的是,我在开发应用程序时遇到了同样的问题。

您是否正确安装了插件?你没有提到是否这样做。

您需要安装cordova whitelist plugin第一的。我通过 npm 做到了这一点。

我还在 config.xml 中添加了对资源的所有访问权限:

  <access origin="*" />
  <allow-intent href="*" />
  <allow-navigation href="*" />

不过,不建议这样做。相反,允许访问应用程序所需的资源。

关于javascript - 将 ionic 应用程序中的域列入白名单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30725984/

相关文章:

android - 我可以在我的 Android 应用程序中使用 JSON 而不是 SQLite 吗?

java - 我试图在屏幕上显示 CountDownTimer,但在 logcat 中得到 "Only one looper can be created per thread"

angularjs - 为什么对 $scope 字段的更改不会传播到另一个字段?

javascript - AngularJS:出现 "[...] is not a function"错误

javascript - 在嵌套 ng-repeat 中的复选框上使用 ng-checked 始终为 true

javascript - 仅针对外部站点触发 onbeforeunload 确认警报

javascript - JavaScript 中的比较运算符

java - Android 中字符串到整数的高效映射

javascript - Paper.js 中的事件处理程序

javascript - 如何检查对象中的数组是否都是空的?