Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic 3.2无法在IOS应用程序中加载json_Ios_Json_Ionic Framework_Ionic3 - Fatal编程技术网

Ionic 3.2无法在IOS应用程序中加载json

Ionic 3.2无法在IOS应用程序中加载json,ios,json,ionic-framework,ionic3,Ios,Json,Ionic Framework,Ionic3,我的应用程序需要加载json数据,这可以在浏览器(ionic serve)和Android应用程序(apk)中使用,但json不会加载到我的IOS应用程序(ipa)中 我正在使用Ionic Pro构建应用程序,以下是相关版本号: |macOS版本| 10.13.2| |Xcode版本| Xcode 9.2| ||构建版本9C40b| |Node.js版本| v8.11.1| |Cordova CLI版本| 7.1.0| |npm版本| 5.6.0 目前,我的客户机正在将一个.json文件推送到他

我的应用程序需要加载json数据,这可以在浏览器(ionic serve)和Android应用程序(apk)中使用,但json不会加载到我的IOS应用程序(ipa)中

我正在使用Ionic Pro构建应用程序,以下是相关版本号: |macOS版本| 10.13.2| |Xcode版本| Xcode 9.2| ||构建版本9C40b| |Node.js版本| v8.11.1| |Cordova CLI版本| 7.1.0| |npm版本| 5.6.0

目前,我的客户机正在将一个.json文件推送到他的web服务器,我正在从那里读取它。这是我们希望继续使用的过程,但是我也尝试过加载本地存储在应用程序中的json,并从firebase获取json(请参阅代码中的2行注释)。这三种方法都可以在浏览器/Android中使用,但在IOS中无法使用

这是我的提供者中应该加载json的代码(仅相关部分,public repo中的完整代码):

从'@angular/core'导入{Injectable};
从'@angular/common/http'导入{HttpClient};
从'@ionic/Storage'导入{Storage};
从“rxjs/Observable”导入{Observable};
@可注射()
导出类数据提供程序{
资料:有;
sitePrefix:字符串=”http://xxxxxx.com/app-data/";
//sitePrefix:字符串=”https://xxxx.firebaseapp.com/";
//sitePrefix:string=“assets/”;
城市:数组=[]
currentCityID:number=-1;
currentCity:any={};
currentStory:数字=0;
构造函数(公共http:HttpClient,公共存储:存储){
这个.load();
}
加载(){
let data:Observable=this.http.get(this.sitePrefix+'data/data5.json');
data.subscribe(结果=>{
这个数据=结果;
set('localdata',JSON.stringify(this.data));
});
}
}

您可能会发现我在此线程上建议的解决方案很有帮助
https://stackoverflow.com/questions/48689049/ngx-translate-not-working-on-ios-device/62694449#62694449

您能上传错误日志吗?没有错误,数据就是无法加载。在构建过程中会出现许多弃用警告。我通过在rest服务上公开json来加载数据。如果可能的话,我仍然希望加载实际的json文件。你能检查一下http请求是否成功吗?我不知道怎么做。我在云端编译,因为我没有Mac电脑。我在iphone上运行apk,但是没有Mac我无法调试。至少我不知道怎么做。此外,如果可能的话,我不希望从资产加载,我的第一选择是从网站加载。欢迎链接到解决方案,但请确保您的答案在没有它的情况下是有用的。这样他们就会明白为什么会有这样的页面,然后引用你链接到的页面中最相关的部分,以防目标页面不可用。
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Storage } from '@ionic/storage';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class DataProvider {

  data: any;
  sitePrefix: string = "http://xxxxxx.com/app-data/";
  //sitePrefix: string = "https://xxxx.firebaseapp.com/";
  //sitePrefix: string = "assets/";
  cities: Array<any> = []
  currentCityID: number = -1;
  currentCity: any = {};
  currentStory: number = 0;

  constructor(public http: HttpClient, public storage:Storage) {
    this.load();
  }

  load() {
    let data:Observable<any> = this.http.get(this.sitePrefix+'data/data5.json');
    data.subscribe(result => {
      this.data = result;
      this.storage.set('localdata', JSON.stringify(this.data));
    });
  }
}