首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >$http进入离子不工作的真实设备,甚至科多瓦-插件-白名单被安装。

$http进入离子不工作的真实设备,甚至科多瓦-插件-白名单被安装。
EN

Stack Overflow用户
提问于 2017-02-13 06:05:26
回答 2查看 862关注 0票数 0

我正在创建一个使用$http get从远程服务器获取json值的离子型应用程序。当我在浏览器上运行它时,它会显示数据,而不是在真正的Android设备上。我也已经安装了cordova-plugin-whitelist

这是我在index.html上的代码

代码语言:javascript
运行
复制
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>

  </head>

  <body ng-app="starter">
    <ion-nav-view>
    </ion-nav-view>
  </body>
</html>

controller.js

代码语言:javascript
运行
复制
.controller('ProductsCtrl', function($scope, $ionicModal, $timeout, $http,    $stateParams) {
      console.log("ProductCtrl: prod_id = " + $stateParams.prod_id);
      $scope.host = "xxxx";
      $http.get("http://"+ $scope.host +"/xxxx/xxxx.php?cat_id=" + $stateParams.prod_id)
      .then(function(response) {
        $scope.products = response.data;
      })
      .error(function(data, status, headers,config){
        console.log('data error');
      })
      .then(function(result){
        things = result.data;
      });
})

config.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.xxxxxxx" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>XXXX</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="you@example.com" href="http://example.com/">
      Your Name Here
  </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="SplashScreenDelay" value="2000"/>
  <preference name="FadeSplashScreenDuration" value="2000"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  <allow-navigation href="http://xxxx.com/*" />
</widget>

正如您在index.html中所看到的,我已经将<meta>标记放在我看到的here的其他帖子上。

代码语言:javascript
运行
复制
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

我还试图卸载和重新安装cordova-plugin-whitelist,但没有什么改变。

cordova plugin remove cordova-plugin-whitelist

cordova plugin add cordova-plugin-whitelist

这些是显示在控制台上的错误。大多数都是404,就像这样:

代码语言:javascript
运行
复制
Failed to load resource: net::ERR_NAME_NOT_RESOLVED

但这次可能是因为<meta> ..。

代码语言:javascript
运行
复制
Refused to load the script 'http://localhost:35729/livereload.js?snipver=1' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'".
(anonymous function) @ localhost:8100/?ionicplatform=ios:98

请帮忙..。提前谢谢..。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-24 01:14:09

上一次我找到了答案,但我现在就把它发出去。我通常使用Ionic运行我的android应用程序,但是当我从控制台(ionic run android)运行我的应用程序时,我注意到了这一点:

“使用这个版本的Cordova和旧版本的corodva-android是不可取的。考虑升级到cordova-android@5.0.0或更高版本。”

所以我刚升级了科多瓦:

代码语言:javascript
运行
复制
cordova platform remove android
cordova platform add android@5.X.X

最后终于成功了。

票数 0
EN

Stack Overflow用户

发布于 2017-02-13 07:46:10

我使用这个作为我的元标记,它处理所有这样的事情。试试这个,让我知道它是有效的。

代码语言:javascript
运行
复制
 <meta http-equiv="Content-Security-Policy" content="default-src *; img-src *;style-src * &apos;unsafe-inline&apos;; script-src * &apos;unsafe-inline&apos; &apos;unsafe-eval&apos;">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42197584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档