我正在使用chrisben imgcache.js插件来缓存图像,
自从更改为WKWebview以来,该插件已停止为我工作。我已切换到v2.1.1,该版本在Android上运行正常。我正在使用带有以下插件的Cordova
cordova-plugin-wkwebview-engine:1.2.1 cordova-plugin-wkwebview-file-xhr:2.1.4
从控制台注意到的以下内容表示文件已正确下载/存储,但在获取文件时会失败。
> [Log] INFO: Download complete:
> file:///Users/shadow4768/Library/Developer/CoreSimulator/Devices/3965C47C-7718-48C3-82ED-DF9A2CCB3989/data/Containers/Data/Application/3BFC0F90-F7D4-4DFA-8648-0F440929F835/Library/NoCloud/imgcache/5b1950b1ee383f3fdd0e51bf84dfdbd505006d79
> (cordova.js, line 1540) [Log] INFO: Cached file size: 37161
> (cordova.js, line 1540) [Log] INFO: current size: 2533404 (cordova.js,
> line 1540) [Log] INFO: com.apple.MobileBackup metadata set
> (cordova.js, line 1540) [Log] INFO: File
> getdocument?documentid=41623&width=300 loaded from cache (cordova.js,
> line 1540) [Error] Failed to load resource: unsupported URL
> cdvfile://localhost/library-nosync/imgcache/91c59e590d88a60c252d8281aa165be35a7d5798
我发现的唯一解决方案与离子有关,
最初,我认为下面的代码是一个修复程序,以意识到它可能与我正在使用的功能不兼容,因为现在只有某些功能可以正常工作。
ImgCache.getCachedFileURL(src,
(originalUrl, cacheUrl) => {
const file = new File();
const cacheFileUrl = cacheUrl.replace('cdvfile://localhost/persistent/', file.documentsDirectory);
const localServerFileUrl = cacheFileUrl.replace('file://', 'http://localhost:8080');
//localServerFileUrl contains the loadable url
resolve(localServerFileUrl);
},
(e) => {
console.error('img-cache-error:', e);
reject(e)
});
任何有关如何解决此问题的想法将不胜感激。