1丶微信小程序之文件下载并预览兼容ios出现的问题
下面展示一些 内联代码片
。
一开始调用wx.downloadFile下载文件获取微信的一个可访问的文件地址并通过 wx.openDocument打开生成的文件地址,在安卓中是能直接打开预览,在ios中需要加fileType,比如是word,fileType就是‘word’文件,下面示例是根据我实际业务场景获取到的文件类型,不加fileType在苹果中就没法打开。
// 下载附件
downFile(e){
console.log(e);
// console.log(e.currentTarget.dataset.id);
wx.downloadFile({
url: e.currentTarget.dataset.accessurlpath, //仅为示例,并非真实的资源
success: function(res) {
console.log(res)
console.log(res.tempFilePath.split('.'));
let fileArr = res.tempFilePath.split('.')
wx.openDocument({
fileType: e.currentTarget.dataset.type,
filePath: res.tempFilePath,
success(){
// Toast('文件打开成功')
}
})
// wx.playVoice({
// filePath: res.tempFilePath
// })
}
})
},
// An highlighted block
// 下载附件
downFile(e){
console.log(e);
// console.log(e.currentTarget.dataset.id);
wx.downloadFile({
url: e.currentTarget.dataset.accessurlpath, //当前文件的url
success: function(res) {
console.log(res)
console.log(res.tempFilePath.split('.'));
let fileArr = res.tempFilePath.split('.')
wx.openDocument({
fileType: e.currentTarget.dataset.type, // **此处为兼容ios无法打开预览的关键**
filePath: res.tempFilePath,
success(){
// Toast('文件打开成功')
}
})
// wx.playVoice({
// filePath: res.tempFilePath
// })
}
})
},
2丶当我作为微信开发者工具的开发用户选择真机调试让其他人扫码调试之后,由于其他人没有正确结束调试,导致下次再点真机调试生成的二维码一直显示已结束请重新开始,亲测有效解决方法
用扫码真机调试的人的微信号登录微信开发者工具再次进行真机调试就没问题了(当前我觉得前提应该是这个用户应该也需要是有权限参与当前微信小程序开发的)