Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229670

Testflight and Files under documentsDirectory (downloaded using FileTransfer plugin)

$
0
0

Hi,

We are building an hybrid app that is working very well on Android and now our team is pushing it to the App Store. At the moment we are testing the app on Testflight and everything was working just fine until we realize that the files that our app downloads for offline puposes are being removed somehow after the app is updated.
My question is if it’s a Testflight issue or IOS situation, lets say Testflight removes files under cordova.file.documentsDirectory when it updates the app for us that’s ok, we just need to logout and login again and the synchronization will do its own work.
But if it’s an IOS issue then we are having trouble to understand whats wrong, because the files (mainly Images) they all appear after the synchronization process at first glance, it’s just when the app is updated that the issue happens.

Another thing that we find weird is that the native storage where we store user’s detail and stuff is beign kept untouched after the updates. I know that probably it’s a different storage but i find the it’s a weird behavior to clean apps folder.

A sample of the code:

Constructor:

constructor(private http: Http,
              private transfer: FileTransfer,
              private events: Events,
              private storage: Storage,
              private rollbar: RollbarService,
              private network: Network,
              private platform: Platform) {
    this.download_in_progress = false;
    this.platform.ready().then(() => {
      if (this.platform.is('ios')) {
        this.storageDirectory = cordova.file.documentsDirectory.replace(/^file:\/\//, '');
      } else if (this.platform.is('android')) {
        this.storageDirectory = cordova.file.dataDirectory;
      } else {
        return this.downloadComplete();
      }
    });
    window.setInterval(() => {
      this.checkHash(); // Checking hash for new files
    }, 60000)
  }

Downloads:

/**
   * Downloading a file
   * @param src Origem (Remote URL)
   * @param target Destino (Local URL)
   * @param description (Item description)
   * @param basic (Basic file)
   * @param is_video (It's a video?)
   */
  downloadFile(src: string, target: string, description: string, basic: boolean = false, is_video: boolean = false, retry: boolean = false) {
    const fileTransfer: FileTransferObject = this.transfer.create();
    console.log('Downloading ' + src + ' to ' + target);
    fileTransfer.download(config.urlSytem + src, target).then((entry) => {
      console.log('Downloaded ' + target);
      this.downloaded++;
      if (is_video) {
        this.downloaded += this.video_weight;
      }
      if (this.downloaded == this.total_files) {
        this.downloadComplete();
      }
    }, (error) => {
      if (!retry) { // Retry the download one time only
        this.downloadFile(src, target, description, basic, is_video, true);
      } else {
        this.error += 'There was an issue downloading the file: ' + description + '. Erro: ' + JSON.stringify(error) + '\n';
        this.errors++; // Storing errors
        this.downloaded++;
        if (is_video) {
          this.downloaded += this.video_weight;
        }
        if (this.downloaded == this.total_files) {
          this.downloadComplete();
        }
      }
    });
  }

Viewing all articles
Browse latest Browse all 229670

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>