uniaapp实现安卓端兼容ios打开pdf文档
//判断是安卓还是ios进行兼容性打开pdf等文件Api.prototype.xiaoyanDoc=function(url,type){switch(uni.getSystem
//判断是安卓还是ios进行兼容性打开pdf等文件
Api.prototype.xiaoyanDoc = function(url,type) {
switch (uni.getSystemInfoSync().platform) {
case "android":
console.log("安卓");
// 这里直接调用原生的方法,我们上面定义的
this.opendoc(url,type);
break;
case "ios":
console.log("IOS");
//这里跳转web-view页面
uni.navigateTo({
url: "/pages/webview/open_pdf?url=" + url,
});
break;
default:
this.opendoc(url,type);
break;
}
}
//打开文档
Api.prototype.opendoc = function(src,type){
uni.showLoading({
title: '正在加载文件...',
mask: true
})
uni.downloadFile({
url: src,
success: function(res) {
uni.hideLoading()
let filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
fileType: type?type:'pdf',
success: function(resa) {
console.log('打开文档成功')
},
});
},
fail() {
uni.hideLoading()
uni.showToast({
icon: 'none',
title:'文件下载失败,请重试'
})
}
});
}
相关文章
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~