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

images stopped loading for Marshmallow / API 23 #170

Open souly1 opened 8 years ago

souly1 commented 8 years ago

HI, Seen others opened a similar issue but none with the exact same this and none with a solution or changes to plugin: After poking around I found that Android's Marshmallow API 23 does not work with imgcache.js, the reason is that they changed the permissions mechanism. Tweaking and updating the cordova file plugin it started working again but now requests permissions to work with the storage. Even if this would be considered OK, a user may easily deny permissions and then imgCache.js does not have any fallback implementation (for example: not try to work with cache mechanism and always load remote image instead) and no image is seen. The example solution above would be a fast and simple solution but a much better one is use the folders which do not require permissions, such as the applications storage directory. What do you think @chrisben ? is this possible at all (maybe issue with hybrid apps?)? and if you think it is, would it be complicated to introduce the change into imgCache.js ?

Thanks

P.S to make it work at least with requesting permissions I had to change:

preference name="AndroidPersistentFileLocation" value="Compatibility"

to:

preference name="AndroidPersistentFileLocation" value="Internal"

In the config.xml

EDIT: it seems that imgCache.js indeed does take care of the failure event of loading from cache and the problem was in angular-imgcache.js, a pull request solving the issue has been done there long ago but it seems the file is no longer maintained. Never the less, it would be great if we could avoid permission request completely.

EDIT 2: Just finished changing the code a bit and tested it with API 23, Marshmallow and older versions with fresh install and upgrade, with value="Compatibility" and value="Internal" and it works. Issued a pull request, based on your version 1.0.0: https://github.com/chrisben/imgcache.js/pull/171 take a look, tell me if I missed anything.

Thanks.

P.S I keep getting WARN: com.apple.MobileBackup metadata could not be set is this ok?

rafaismyname commented 8 years ago

Hey man, thanks for this :)

but i tried to use your version, and still fails :(

running with gapdebug shows me that it tries to create the cache, but the cache is broken...

this is my function to try cache image by url and and retrieve the cached url (or not):

getUrl: function(url){
    return new Promise(function(resolve, reject){
      ImgCache.isCached(url, function(path, success) {
        if (success){
          ImgCache.getCachedFileURL(url, function(src, entry){
            return resolve(entry);
          }, function(){ return resolve(url); });
        } else {
          ImgCache.cacheFile(url, function(entry){
            return resolve(entry);
          }, function(){ return resolve(url); });
        }
      });
    });
  }
rafaismyname commented 8 years ago

Actually... nevermind... Adding to config.xml

<allow-intent href="cdvfile://*" />
<access origin="cdvfile://*" /> 

solved everything! sorry to bother!

muhammadsamir11 commented 8 years ago

I added

<allow-intent href="cdvfile://*" />
<access origin="cdvfile://*" /> 

to config xml but it didn't work

ERROR: Download error code: null
Cache size 0

Android 6.0.1 Cordova 6.3.1