chrisben / imgcache.js

JS library based on the File API to cache images for offline recovery (target: cordova/phonegap & chrome)
Other
826 stars 216 forks source link

ImgCache is not working in IOS #204

Open distribuidoralemes opened 7 years ago

distribuidoralemes commented 7 years ago

I'm using imgcahe on an application with ionic 2.

It was working well but today I received the error:

Your browser does not support the html5 File API

There is a solution for this?

ggregg commented 7 years ago

Add cordova plugin : file, file-transfer, device :)

gustavoschmidt commented 7 years ago

I have the same problem in iOS even after installing the plugins (file, file-transfer, device). @distribuidoralemes Are you using cordova-plugin-wkwebview-engine?

I think the error might be related to this bug: https://issues.apache.org/jira/browse/CB-11004?jql=text%20~%20%22wkwebview%20file%22

ggregg commented 7 years ago

I use this plugins

<plugin name="cordova-plugin-crosswalk-webview" spec="~2.3.0" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova-plugin-network-information" spec="~1.3.1" />
<plugin name="cordova-plugin-file" spec="~4.3.2" />
<plugin name="cordova-plugin-keyboard" spec="~1.1.5" />
<plugin name="cordova-plugin-file-transfer" spec="~1.6.2" />
<plugin name="cordova-plugin-device" spec="~1.1.5" />
<plugin name="cordova-plugin-console" spec="~1.0.6" />

All work fine ...

Are you sure that cordova object is defined ?

ggregg commented 7 years ago

If it could help, I had exactly the same error if I initialize ImgCache before Cordova. Now I use a promise like this :

export const ImgCacheInitPromise = new Promise((resolve, reject) => {
    ImgCache.init(() => {
        resolve(ImgCache)
    }, () => {
        reject()
    })
})

Using this way like lazy loading :

ImgCacheInitPromise.then((ImgCache) => {
    //Image cache supported and initialized
    ImgCache.cacheFile(...)
    ...

}, () => {
    //Image cache not supported (debug mode in safari)
    ...
})

Hope :)

ralphcode commented 7 years ago

As above, I hit this when testing on iOS PhoneGap Developer app. I have accidentally commended out the include for Cordova. Try checking and ensuring this in your index;

<script type="text/javascript" src="cordova.js"></script>