ios - 来自外部 url 的 Ionic 5 电容器/角度预览文件
问题描述
我尝试使用 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”,
仅在 IOS 模拟器 + Real IOS 设备上注意到此行为。知道这里发生了什么吗?
解决方案
链接中的特殊字符 (%2F)是问题的原因。
为了快速获胜;在处理之前更改链接或清理。
在这种情况下url.replace('%2F', '/')
应该工作。
但是,另一个链接可能包含不同的字符。在没有 100% 确定的情况下,值得一试decodeURI,即decodeURI(url)
.
推荐阅读
- html - 试图在中间有一个带有可滚动内容的左右*响应*侧边栏,滚动条在右侧
- excel - Excel:使用具有多个结果的多个条件进行搜索
- c++ - 在C++中,当模板参数没有出现在下面的类或函数声明中时,它有什么用?
- oracle - 我们可以在 oracle 中找到外部表的 ddl 脚本(任何系统表)
- c - 在 C 输入重定向问题中实现 shell
- java - 在当前主题中找不到“@attr/textappearancebutton”
- linux - 通过递增值和乘法进行文本操作
- java - 为什么我的素数测试在 1 之后停止并且似乎无法继续?
- asp-classic - Zoom Meeting API - msxml6.dll 错误“80070005”访问被拒绝
- amazon-web-services - 多可用区环境下的实例自动伸缩