PhoneGap and iOS 8: Failed to load local files ONLY after updating my app

I am developing PhoneGap


where a user can navigate some pages served by a server. When the user clicks on these pages, the application loads all files ( HTML


, JS

etc.) and save them iPad

. This way, if the user tries to access those pages offline

, local files are served.

This app worked fine at iOS

7. Yesterday I decided to upgrade mine iPad

to iOS

8, and at first I thought it worked: I can download files, go offline and still navigate pages using local files. The only error I am getting is Console


[Error] Deprecated attempt to access property 'userAgent' on a non-Navigator object.


The problem occurs when I update my app or use "localgap localus iOS" with the app installed. Whenever I do this, the application becomes unable to load local files:

Failed to load resource: The requested URL was not found on this server. 


The files are there, I can read them with the plugin File

, but the WebView cannot load them. I refer to them as follows:

<img src="file://localhost/var/mobile/Containers/Data/Application/7A3590E8-C78A-4F45-B5B9-51FD0BAFE524/Library/files/pages/7/7a56ab3cfa56fbd1b9c4becbf5dca4a2.jpg" >


I tried using both Library

and Compatibility

how iosPersistentFileLocation

but the result is the same. I mark all uploaded files as "not backed up" to prevent them from being included in iCloud


fileEntry.setMetadata(function(){}, function(){}, {"": 1});


At first I thought it was caused by a known error for loading local files at iOS

8, but my app is loading them, it just stops working after updating the app.

Have me PhoneGap

and everyone plugins

updated to the latest version. I also tried using Cordova

and it will happen.

Does anyone know how I can resolve this issue or where should I report this error?



source to share

2 answers

I managed to solve it! I used fileEntry.toURL to use file urls in my HTML file. If i use



it works great.

With an internal url, the urls look like this:





I faced the same problem and I was able to solve it. In my case, my problem was that every time I update the application, the new application has a different ID than the last one. For example, the path for an older application:



And the new one:



So even though my PDFs were still in the app data store, I was using the wrong path as the app generated a new app id. I solved this by creating a new function that updates my path every time there is an update. I find the app id using:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);

function onFileSystemSuccess(fileSystem) {
    //Do what you need here


The file system is an object that contains the nativeURL inside the root.

Hope this helps!



All Articles