收藏
回答

ios系统中openDocument API调用成功但是打开文件无反应

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug openDocument 客户端 7.0.4 2.7.1

- 当前 Bug 的表现(可附上截图)


- 预期表现


- 复现路径


- 提供一个最简复现 Demo


ios系统中openDocument  API调用成功但是打开文件无反应

wx.downloadFile({

url:  path,

success: function (res) {

console.log(res)

var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用

var imgtypes = ['bmp', 'jpg', 'png', 'gif', 'tif', 'fpx', 'svg', 'jpeg'];

for (var idx in imgtypes) {

if (Path.endsWith(imgtypes[idx])) {

wx.previewImage({

urls: [Path],

})

return;

}

}

wx.openDocument({

filePath: Path,

success: function (res) {

console.log('打开成功');

}, fail: function (res) {

console.log(res);

}

})

},

fail: function (res) {

console.log(res);

},

complete: function () {

wx.hideLoading();

}

});


最后一次编辑于  2019-06-11
回答关注问题邀请回答
收藏

3 个回答

  • 2019-08-07

    看看这个是否能解决呢:

    https://my.oschina.net/tianma3798/blog/3084598

    2019-08-07
    有用
    回复
  • duoke
    duoke
    2019-06-11

    pat = pat.replace(/\\/g ,'/');

    var titlePath = pat.substring(pat.lastIndexOf('/') + 1);

    // wx.navigateTo({

    //   url: '../web_view/web_view?url=' + pat,

    // })

    // wx.hideLoading();

    wx.downloadFile({

    url: pat,

    filePath: wx.env.USER_DATA_PATH + '/' + titlePath,

    success: function (res) {

    wx.hideLoading();

    console.log(res)

    var Path = res.filePath; //返回的文件临时地址,用于后面打开本地预览所用

    var imgtypes = ['bmp', 'jpg', 'png', 'gif', 'tif', 'fpx', 'svg', 'jpeg'];

    for (var idx in imgtypes) {

    if (Path.endsWith(imgtypes[idx])) {

    wx.previewImage({

    urls: [Path],

    })

    return;

    }

    }

    var fs = wx.getFileSystemManager();

    console.log("重命名地址:", wx.env.USER_DATA_PATH)

    fs.rename({

    oldPath: Path,

    newPath: wx.env.USER_DATA_PATH + '/' + titlePath,

    success: function(res){

    console.log(res)

    wx.openDocument({

    filePath: wx.env.USER_DATA_PATH + '/' + titlePath,

    success: function (res) {

    console.log('打开文档成功');

    console.log(res);

    },

    fail: function (res) {

    wx.showToast({

    title: 'fail',

    icon: 'none'

    })

    console.log('fail')

    console.log(res)

    },

    complete: function (res) {

    console.log('complete')

    console.log(res)

    }

    })

    },

    fail:function(res){

    console.log(res)

    wx.showToast({

    title: '文件重命名失败',

    icon: 'none'

    })

    }

    });


    },

    fail: function (res) {

    console.log(res);

    },

    complete: function () {

    wx.hideLoading();

    }

    });


    2019-06-11
    有用
    回复 1
  • 是小白啊
    是小白啊
    2019-06-11

    麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2019-06-11
    有用
    回复
登录 后发表内容