我已经尝试过Previewanyfile cordova插件以从Ionic 5应用程序中的外部URL打开文件。它在android上运行良好,但在IOS上我注意到有时无法预览/打开PDF文件。只是一个带有文件名的灰色屏幕。但是奇怪的是有些PDF文件打开了。文件预览屏幕
previewProductDocument(url: string) {
const loading = await this.loadingController.create({
message: 'Loading document...',
});
loading.present().then(() => {
this.previewAnyFile.preview(url).then((res) => {
loading.dismiss();
}).catch((err) => {
loading.dismiss();
this.presentToast('Error previewing the document try later', 'danger');
});
});
}
这是我使用过的插件https://ionicframework.com/docs/native/preview-any-file
电容器版本“ @ capacitor / core”:“ ^ 2.2.0”,
仅在Real IOS设备上的IOS模拟器+中注意到此行为。知道这里发生了什么吗?
链接中的特殊字符(%2F)是导致此问题的原因。
为了快速获胜;在处理之前,请更改链接或进行清理。
在这种情况下url.replace('%2F', '/')
应该可以工作。
但是,另一个链接可能包含不同的字符。如果没有100%的确定,则值得尝试一下解码URI,它是decodeURI(url)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句