cordova.plugins.fileOpener2.showOpenWithDialog适配ios android注意事项

16 篇文章 2 订阅
8 篇文章 0 订阅

项目场景:

ios附件打开 注意事项


注意事项:

config.xml 记得配置

<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />

在这里插入图片描述
一直调试cordova.file.externalDataDirectory iOS显示为null对照上述图片 才发现
downloadFile这里不做细说 百度有类似文档

    const self = this
    window.resolveLocalFileSystemURL(_this.isIos ? cordova.file.tempDirectory : cordova.file.externalDataDirectory, (fs) => {
      fs.getFile(fileName, { create: true, exclusive: true }, fileEntry => {
        self.downloadFile(uri, fileEntry, _this)
      }, e => {
        console.log(e)
        // eslint-disable-next-line no-undef
        fs.getFile(
          fileName,
          { create: false },
          fileEntry => {
            // 成功读取文件后调用cordova-plugin-file-opener2插件打开文件
            fileEntry.file(data => {
              self.preView(fileEntry, data, _this)
            })
          },
          // eslint-disable-next-line handle-callback-err
          error => {
          })
      })
      // eslint-disable-next-line handle-callback-err
    }, error => {
    })

细说这个方法preView

  preView (fileEntry, data, _this) {
    // eslint-disable-next-line no-undef
    const url = _this.isIos ? fileEntry.toURL() : fileEntry.toInternalURL()
    cordova.plugins.fileOpener2.showOpenWithDialog(decodeURIComponent(url), data.type, {
      success: (e) => {
        console.log('file opened successfully')
      },
      error: (e) => {
        console.log('Error status: ' + e.status + ' - Error message: ' + e.message)
      },
      position: [0, 0]
    })
  },

注意iOS获取URL的方法

    fileTransfer.download(uri, fileEntry.toURL(), entry => {

这里的source uri 不要是中文 记得编译下

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值