Angular&Ionic,HTTP无法在真实设备IOS中工作

Nim*_*ima 11 angularjs ionic-framework ionic

我在我的应用程序中遇到问题,当我在本地主机中运行应用程序时它没有问题,我可以看到频道列表但是当我尝试通过物理设备测试应用程序时它没有显示任何内容.我认为问题来自我用来通过http发送json数据的方法.

(function () {
'use strict';

angular.module('testApp').controller('ChannelCtrl', ['$state', 'testApi', ChannelCtrl]);

function ChannelCtrl($state, testApi) {
    var vm = this;

myscreenApi.getChannels().then(function(data){
         vm.channels = data;
     });

    vm.selectLeague = function(id){
        testApi.setChannelId(id);
        $state.go("app.video");
    }

};
})();
Run Code Online (Sandbox Code Playgroud)

这是我获取通道数据的功能

function getChannels() {
        var deferred = $q.defer(),
            cacheKey = "leagues",
            ChannelsData = null;

        if (ChannelsData) {
            console.log("Found data inside cache", ChannelsData);
            deferred.resolve(ChannelsData);
            $window.alert("From Cache");
        } else {
            $http.get("http://example.com/api/videos/getchannels")
                .success(function(data) {
                    console.log("Received data via HTTP");
                    self.leaguesCache.put(cacheKey, data);
                    $window.alert("From HTTP");
                    deferred.resolve(data);
                })
                .error(function(dataerr) {
                    console.log("Error while making HTTP call.");
                    $window.alert("Error baba daram " + dataerr);
                    deferred.reject();
                });
        }
        return deferred.promise;
    }
Run Code Online (Sandbox Code Playgroud)

当我使用JSON.parse()发送数据时,它可以正常工作.

vm.channels = JSON.parse('[{"Name":"MyScreen News","ID":46,"Thumbnail":"CB46.jpg","Videos":null}]');
Run Code Online (Sandbox Code Playgroud)

总的来说,我使用了由JSON发送数据的ASP.NET Web API.该应用程序在我们的桌面上运行良好,但运行的应用程序无法从我们的主机检索数据.而且,当我直接在程序中注入数据时,它可以在两个平台上工作.另外,离子配置文件如下所示:

  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="BackupWebStorage" value="none"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
Run Code Online (Sandbox Code Playgroud)

就这样.;)

Lef*_*tyX 12

如果您使用的是最新版本的cordova,则可能需要安装cordova插件白名单:

cordova plugin add cordova-plugin-whitelist
Run Code Online (Sandbox Code Playgroud)

如果您使用的是IIS Express,则可能会发现一些问题.
我在这里详细解释一些.