0

My app needs to load json data, and this works in browser (ionic serve), and in my Android app (apk), but the json won't load in my IOS app (ipa).

I am building the app with Ionic Pro, here are relevent version numbers: | macOS version | 10.13.2 | | Xcode version | Xcode 9.2 | | | Build version 9C40b | | Node.js version | v8.11.1 | | Cordova CLI version | 7.1.0 | | npm version | 5.6.0

Currently, my client is pushing a .json file to his web server, and I am reading it from there. This is the process we would prefer to continue using, however I have also tried loading json stored locally in the app, and fetching json from firebase (see 2 commented-out lines in code). All 3 methods work in browser/Android, and fail in IOS.

This is the code in my provider that is supposed to load the json (only the relevant parts, full code in public 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));
    });
  }
}
  • Can you upload the error log? – Hyuck Kang Jul 07 '18 at 15:20
  • There are no errors, the data just doesn't load. There are many deprecation warnings during the build. – user1684346 Jul 07 '18 at 15:42
  • I managed to load the data by exposing the json on a rest service. I would still prefer to load the actual json file if possible. – user1684346 Jul 07 '18 at 15:44
  • In my case, **json** from `assets` works well in every platforms. Can you check if the http request success or not? – Hyuck Kang Jul 07 '18 at 15:55
  • I'm not sure how to do that. I am compiling in the cloud because I don't have a Mac. I'm running the apk on an iphone, but without a Mac I am not able to debug. At least I don't know how to anyways. Also, I'd prefer not to load from assets if possible, my first choice would be to load from the website. – user1684346 Jul 08 '18 at 10:35
  • By the way, are you saying that you were able to load from the "assets" folder using my code from the repo? Or, are you saying that you have been able to do it yourself in the past? I know that it is possible to load from assets, I just don't know what is wrong with my code. – user1684346 Jul 08 '18 at 11:06
  • I did it by myself in the past and also fetched **json** from the webserver. I think there are so many possible reason why your code doesn't work. So, it seems impossible to solve the issue without debugging process. – Hyuck Kang Jul 08 '18 at 14:58

1 Answers1

0

you might find my suggested solution on this thread helpful https://stackoverflow.com/questions/48689049/ngx-translate-not-working-on-ios-device/62694449#62694449

p90n33r
  • 1,671
  • 3
  • 9
  • 6
  • A link to a solution is welcome, but please ensure your answer is useful without it. [Add context around the link](https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers/8259#8259) so thers will understand why it’s there, then quote the most relevant parts of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](https://stackoverflow.com/help/deleted-answers) – Leogout Jul 02 '20 at 11:42