我正在上传PDF在我的应用程序到Firebase存储。
现在我想在浏览器中打开我的应用程序中的PDF格式。为此,我尝试像这样使用启动器:
Future<void> _launchURL(
BuildContext context, {
required String url,
String? errorMessage,
}) async {
if (await canLaunch(url) == true) {
await launch(Uri.encodeFull(url));
}
}但是当打开URL时,我得到以下信息:
{
"error": {
"code": 403,
"message": "Permission denied."
}
}如果将我的Storage Rules设置为allow: read, write;,我将得到一个404-error。将我的launch更改为:
Future<void> _launchURL(
BuildContext context, {
required String url,
String? errorMessage,
}) async {
if (await canLaunch(url) == true) {
await launch(url); // <- without encoding
}
}我得到了一个Platform-Exeption
未处理的异常:PlatformException(错误,启动https://firebasestorage.googleapis.com/v0/b/appflug.appspot.com/o/studs%2FladSXGLivhRtVlJh3vogjXoxCdj1%2FlanguageTest%2FwIcon.pdf?alt=media&token=403f9631-58ed-4931-b76c-b9e6253e7d25时出错,null,null)
,但它正在网络上工作!。它实际上也是在我的iOS设备上打开我的浏览器中的PDF,但是它正在抛出.
我遗漏了什么?如何在downloadUrl、Android和Web上的浏览器中从Firebase Storage打开一个iOS?
发布于 2022-04-30 20:40:47
这两种方法都适用于我使用6.1.0版本的启动器
Future<void> launchInWebViewWithoutJavaScript(String url) async {
final Uri toLaunch = Uri.parse(url);
if (!await launchUrl(
toLaunch,
mode: LaunchMode.inAppWebView,
webViewConfiguration: const WebViewConfiguration(enableJavaScript: false),
)) {
throw 'Could not launch $url';
}
}然后你也可以用这个:
Future<void> launchInWebViewOrVC(String url) async {
final Uri toLaunch = Uri.parse(url);
if (!await launchUrl(
toLaunch,
mode: LaunchMode.inAppWebView,
webViewConfiguration: const WebViewConfiguration(
headers: <String, String>{'my_header_key': 'my_header_value'}),
)) {
throw 'Could not launch $url';
}
}https://stackoverflow.com/questions/70784391
复制相似问题