0
votes

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));
    });
  }
}
1
Can you upload the error log? - Hyuck Kang
There are no errors, the data just doesn't load. There are many deprecation warnings during the build. - user1684346
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
In my case, json from assets works well in every platforms. Can you check if the http request success or not? - Hyuck Kang
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

1 Answers

0
votes

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