Flutter:webview_flutter在iOS上仅显示为空白(白色)

xt0899hw  于 2023-02-20  发布在  Flutter
关注(0)|答案(1)|浏览(702)
    • bounty将在5天后过期**。回答此问题可获得+50声望奖励。Cedric希望引起更多人关注此问题。

我让它在Android上工作,WebViewWidget与HTML内容正确显示,没有问题。
对于iOS,它只显示blank/white。我尝试了我在互联网上看到的所有人的建议,这是添加几行到Info.plist,允许iOS中的WKWebView加载和显示http(不安全,不仅仅是https):

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

(我不太清楚这些线条各自的作用)
(^^我还尝试了小写的"yes"和<true/>作为第一个值)
我运行了flutter clean,然后是flutter pub get,删除了Podfile.lock,运行了pod install(在ios文件夹中)很多次,但我仍然无法在iOS上的webview中显示内容(它在Android上有效),只有html内容应该出现的空白区域。
需要特别指出的是,我既不从http也不从https获取html,但我加载了一个String(即html)并将其设置为:

String text = ...
await _controller.loadHtmlString(text);

有没有办法欺骗iOS,让它认为html来自https?
以下是我在控制台中看到的一些常见消息(不是红色,只是普通颜色),我只有在从Android Studio运行应用程序时才会收到这些消息,而不是XCode(在真正的iOS设备上):

[assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
[ProcessSuspension] 0x12d07df20 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=47861, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}

以及:

Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

更新:我发现,即使我使用https,比如_controller.loadRequest(Uri.parse('https://flutter.dev'));,它在iOS上也会显示一个空白/白色页面。

brgchamk

brgchamk1#

我解决了这个问题,这是意料之外的,而且与http/https无关......请参见下面代码中的注解以获得解释

_controller.setNavigationDelegate(
    //...
      onNavigationRequest: (NavigationRequest request) {
        print('onNavigationRequest');
        //I first had this line to prevent redirection to anywhere on the internet via hrefs
        //but this prevented ANYTHING from being displayed
        // return NavigationDecision.prevent;

        return NavigationDecision.navigate; //changed it to this, and it works now
      },
    );

我还从Info.plist中删除了所有这些行,它仍然工作。

相关问题