1***@qq.com
1***@qq.com
  • 发布:2022-07-13 17:06
  • 更新:2022-07-19 08:41
  • 阅读:302

在IOS上使用WEBVIEW,如何在本地网页中载入本地网页的档案?

分类:uni-app

在IOS上使用WEBVIEW,如何在本地网页中载入本地网页的档案?
使用XMLHttpRequest载入本地网页档案在ANDROID上是没有问题,
在IOS上的路径是需要什么处理?

项目:

/hybrid/html/index.html运行的JS代码:

function loadFile(filePath) {  
      var result = null;  
      var xmlhttp = new XMLHttpRequest();  
      xmlhttp.open("GET", filePath, false);  
      xmlhttp.onreadystatechange = function (oEvent) {  
          if (xmlhttp.readyState === 4) {  
              if (xmlhttp.status === 200) {  
                console.log('SUCCESS')  
              } else {  
                 console.log("Error", xmlhttp.statusText,xmlhttp );  
              }  
          }  
      };  
      xmlhttp.send();  
      if (xmlhttp.status==200) {  
        result = xmlhttp.responseText;  
      }else{  
          console.log(xmlhttp);  
      }  
      return result;  
    }  

try{  
    console.log('test.json length:'+loadFile('test.json').length);  
}catch(e){  
    console.log(e)  
}

在ANDROID上是能正常载入:
16:55:47.756 SUCCESS at hybrid/html/index.html:21
16:55:47.787 test.json length:21 at hybrid/html/index.html:36

在IOS上无法载入
16:56:02.947 Error [object XMLHttpRequest]
16:56:02.980 NetworkError: A network error occurred.

2022-07-13 17:06 负责人:无 分享
已邀请:
FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

绝对路径

  • 1***@qq.com (作者)

    使用plus.io.convertLocalFileSystemURL后的路径:

    /var/mobile/Containers/Data/Application/XXAD262F-85F6-46B0-A3BA-XXDF59A4EBXX/Documents/Pandora/apps/HBuilder/www/hybrid/html/test.json


    这绝对路径没问题吧?但也是不行

    2022-07-15 15:26

  • FullStack

    回复 1***@qq.com: 前面再加个 file://

    2022-07-15 16:41

T泰达T

T泰达T

插件市场搜本地http服务器可以解决

BoredApe

BoredApe - 有问题就会有答案。

可以参考下网赚游戏中如何打开本地webview

要回复问题请先登录注册