简体   繁体   English

为什么 webview_flutter 在添加到应用程序(iOS)的情况下不起作用?

[英]Why webview_flutter not working in case of add to app (iOS)?

So I am trying to open a simple webview when a button is clicked.所以我试图在单击按钮时打开一个简单的 webview 。

This is the body of my Scaffold widget:这是我的 Scaffold 小部件的主体:

body: 
WebView(
    initialUrl: "https://www.google.com/",
    javascriptMode: JavascriptMode.unrestricted,
)

The interesting part is when I run this flutter project independently it successfully opens the Webview in the iOS simulator.有趣的是,当我独立运行这个 flutter 项目时,它成功地在 iOS 模拟器中打开了 Webview。 But when I integrated this flutter module into an existing iOS App it doesn't work (Shows a blank screen).但是,当我将此 flutter 模块集成到现有的 iOS 应用程序中时,它不起作用(显示空白屏幕)。 In order to add a flutter module, I have followed this link , the other part of the module works fine.为了添加 flutter 模块,我按照这个链接,模块的其他部分工作正常。

I have already set this in the info.plist for the flutter module:我已经在 flutter 模块的 info.plist 中设置了这个:

<key>io.flutter.embedded_views_preview</key>
<true/>

I have added the following version in pubspec.yaml file:我在pubspec.yaml文件中添加了以下版本:

webview_flutter: ^0.3.22+1

After a few hours of debugging I found that we need to add this key in the iOS project info.plist file rather than putting it into the info.plist in the iOS folder of the flutter module经过几个小时的调试发现我们需要在iOS项目的info.plist文件中添加这个key,而不是放到flutter模块的iOS文件夹下的info.plist中

<key>io.flutter.embedded_views_preview</key>
<true/>

Ive ran into this issue too when using webview_flutter .我在使用webview_flutter时也遇到了这个问题。 Fortunately, the ios setup from flutter_webview_plugin seemed to work.幸运的是,flutter_webview_plugin 中的ios设置似乎有效。 I used this tag in xcode's Info.list:我在 xcode 的 Info.list 中使用了这个标签:

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

Please be mindful that they are currently merging to the official webview_flutter plugin.请注意,它们目前正在合并到官方webview_flutter插件。

If url you're using has some special character.如果您使用的 url 有一些特殊字符。 So,You need to encode the URL like this,所以,你需要像这样编码 URL,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM