首页 > 解决方案 > iOS错误无法加载资源:不支持的URL

问题描述

我正在使用 chrisben imgcache.js 插件来缓存图像,

自从更改为 WKWebview 后,此插件已停止为我工作。我已切换到在 Android 上运行良好的 v2.1.1。我正在使用带有以下插件的 Cordova

科尔多瓦插件 wkwebview 引擎:1.2.1 科尔多瓦插件 wkwebview 文件 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)
    });

任何关于我如何解决这个问题的想法都将不胜感激。

标签: ioscordovawkwebview

解决方案


推荐阅读