Flutter webview http url 在 IOS 中不工作

Flutter webview http url not working in IOS

我在 flutter 中开发 webview。我无法在 IOS 中打开 http url。它在 https 上工作。谁能建议如何克服这个问题。

我输入info.plist

 <key>io.flutter.embedded_views_preview</key>
    <string>YES</string>
     <key>NSAllowsArbitraryLoads</key>
    <true/>

此致, 萨西什

In iOS UIWebview is deprecated so your should your WKWebview.

对于 Flutter,您应该使用以下依赖项:

webview_flutter: 0.3.15+1

导入这个 class :

import 'package:webview_flutter/webview_flutter.dart';

添加此小部件:

@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: new AppBar(
      title: Text(this.title,centerTitle: true
  ),
  body: WebView(
  initialUrl: url,
  onPageFinished:(value){
    setState(() {
      print("====your page is load");
    });
  },
  )
);
}

需要禁用 Apple 传输安全。

  1. 在 Xcode 中打开项目。
  2. 打开Info.plist
  3. Information Property List 添加一个新行(检查 id 它已经存在)

  1. Select App Transport Security Settings
  2. 确保 Allow Arbitrary Loads 设置为 YES

将此添加到您的 Info.plist

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
    </dict>

如果你的 url 有一些特殊的字符。您需要像这样编码 URL,

WebView(
      initialUrl: Uri.encodeFull(EnterUrlHere),
      ...
 )