有几天我一直试图解决这个问题。 angular-imgcache.js模块适用于Android,但不适用于iOS。我可以检查Android上的文件系统和iOS上的app容器。区别在于imgcache目录位于Android上的文件系统的根目录,而iOS的imgcache位于Library/files/imgcache
下。以下是我刷新时在safari远程检查器中看到的消息。
[Log] INFO: LocalFileSystem opened (vendors.min.js, line 852)
[Log] INFO: Local cache folder opened: /imgcache/ (vendors.min.js, line 852)
[Log] INFO: com.apple.MobileBackup metadata set (vendors.min.js, line 852)
[Log] ERROR: Download error source: https://URLPATH (vendors.min.js, line 852)
[Log] ERROR: Download error target: cdvfile://localhost/root/imgcache/c56f69853d5444c697307b96a1eef89a55a64830.jpg (vendors.min.js, line 852)
[Log] ERROR: Download error code: 1 (vendors.min.js, line 852)
[Log] ERROR: Download error source: https://URLPATH (vendors.min.js, line 852)
[Log] ERROR: Download error target: cdvfile://localhost/root/imgcache/be0f1e88a316eb2b049b2bc09fadef9cac2c5e87.jpg (vendors.min.js, line 852)
[Log] ERROR: Download error code: 1 (vendors.min.js, line 852)
初始加载后,我可以通过修改此对象来覆盖filecache操作中使用的imagecache目录
ImgCache.attributes.dirEntry
Object
filesystem: Object
fullPath: "/imgcache/"
isDirectory: true
isFile: false
name: "imgcache"
nativeURL: "file:///var/mobile/Containers/Data/Application/CONTAINER_HASH/Library/files/imgcache/"
__proto__: Object
> ImgCache.attributes.dirEntry.fullPath = ImgCache.attributes.dirEntry.nativeURL
< "file:///var/mobile/Containers/Data/Application/CONTAINER_HASH/Library/files/imgcache/"
> ImgCache.cacheFile("https://URLPATH");
< undefined
[Log] INFO: Download complete: /imgcache/c56f69853d5444c697307b96a1eef89a55a64830.jpg (vendors.min.js, line 852)
[Log] INFO: Cached file size: 14122 (vendors.min.js, line 852)
[Log] INFO: current size: 14122 (vendors.min.js, line 852)
[Log] INFO: com.apple.MobileBackup metadata set (vendors.min.js, line 852)
我尝试在初始化之前以这种方式设置ImgCache但最终导致初始化错误。我的实现有问题或者这个ImgCache在iOS上有错误。这是我的一些配置。
//ImgCache.attributes.dirEntry.fullPath = ImgCache.attributes.filesystem.root.nativeURL;
//ImgCacheProvider.setOption('debug', true);
//imgCache options
// set single options
ImgCacheProvider.setOption('debug', true);
ImgCacheProvider.setOption('usePersistentCache', true);
// or more options at once
ImgCacheProvider.setOptions({
debug: true,
usePersistentCache: true
});
// ImgCache library is initialized automatically,
// but set this option if you are using platform like Ionic -
// in this case we need init imgcache.js manually after device is ready
ImgCacheProvider.manualInit = true;
初始化发生在$ionicPlatform.ready
// PhoneGap application
if (navigator && navigator.splashscreen) {
$ionicPlatform.ready(function() {
console.log('$ionicPlatform');
Analytics.init();
if (phoneCheck.android) {
ionic.Platform.isFullScreen = true;
}
if (phoneCheck.ios) {
setTimeout(function() {
navigator.splashscreen.hide();
ImgCache.$init();
}, 2500);
}
});
}