ios系统中openDocument API调用成功但是打开文件无反应
发布于 5 年前 作者 daina 12551 次浏览 来自 问答
  • 当前 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();

}

});

3 回复

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

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();

}

});

回到顶部