【问题标题】:Ionic 3.2 Cannot load json in IOS appIonic 3.2 无法在 IOS 应用程序中加载 json
【发布时间】:2018-12-15 12:18:25
【问题描述】:

我的应用需要加载 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 条注释掉的行)。所有 3 种方法都在浏览器/Android 中工作,在 IOS 中失败。

这是我的提供程序中应该加载 json 的代码(仅相关部分,公共 repo https://github.com/marvabban/antitour 中的完整代码):

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));
    });
  }
}

【问题讨论】:

  • 可以上传错误日志吗?
  • 没有错误,只是没有加载数据。在构建过程中有许多弃用警告。
  • 我设法通过在休息服务上公开 json 来加载数据。如果可能,我仍然希望加载实际的 json 文件。
  • 就我而言,来自assetsjson 在每个平台上都运行良好。你能检查一下http请求是否成功吗?
  • 我不知道该怎么做。我在云中编译,因为我没有 Mac。我在 iphone 上运行 apk,但没有 Mac 我无法调试。至少我不知道该怎么做。另外,如果可能的话,我不希望从资产加载,我的第一选择是从网站加载。

标签: ios json ionic-framework ionic3


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2016-06-28
  • 2020-02-05
  • 1970-01-01
  • 2017-03-31
  • 1970-01-01
  • 1970-01-01
  • 2021-05-01
  • 2017-07-28
  • 2020-02-15
相关资源
最近更新 更多