jeudi 15 juin 2017

Cordova iOS application directory and file url differs (UUID issue)

I've created a Cordova application that fetches images from a server and saves them to an iPad. However, when trying to display the images in the application, the images will not load. One example of such a file path could be:

file:///var/mobile/Containers/data/Application/FC87E925-9753-4D9F-AE27-54FCF9B0451E/Documents/-media-3405-company.png

However, when inspecting the cordova.file.applicationDirectory variable, I find another path, e.g. (note that the UUID differ even though I'm inspecting both variables in the same run)

file:///var/containers/Bundle/Application/D8266D08-18A4-4293-B78A-B4597FC0C6B8/salesApp.app/

Accordingly to the documentation, the correct path "should" be: (however, that does not work either)

file:///var/mobile/Applications/UUID/Documents/-media-3405-company.png

Here is the code I use to load the images, which are correctly saved to the device

const downloadFile = (url, fileName, callback) => {
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, (fs) => {
          fs.root.getFile(fileName, {
            create: true,
            exclusive: false
          }, (fileEntry) => {
            const fileURL = fileEntry.toURL();
            const fileTransfer = new FileTransfer();
            fileTransfer.download(
              url,
              fileURL,
              (entry) => {
                const file = entry.toURL()
                content.pushObject('Downloaded ' + entry + ' (' + fileName + ') ' + file)
                callback(file)
              },
              (error) => {
                content.pushObject('error ' + error.code + '(' + fileName + ')')
                if (error.code === FileTransferError.CONNECTION_ERR) {
                  downloadFile(url, fileName) // Try again
                } else {
                  decrement(url) // Ignore this file
                }
              }
            )
          }, (error) => {
            alert(2)
          })
      }, () => {
        alert(3)
      })
    }




Aucun commentaire:

Enregistrer un commentaire