`Flutter: webview_flutter` 在 iOS 上只显示空白(白色)。

huangapple go评论75阅读模式
英文:

Flutter: webview_flutter just displays blank (white) on iOS

问题

I got it to work on Android, the WebViewWidget displays correctly with the html content, no problem.

For iOS it just displays blank/white. I tried what I have seen suggested by people all over the internet, which is to add a few lines to Info.plist, that allow the WKWebView in iOS to load and display http (not secure, not only https):

<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
  <key>NSAllowsArbitraryLoadsInWebContent</key>
  <true/>
</dict>
(^^I don't really know what these lines individually do)
(^^I have also tried lowercase "yes" and `<true/>` as values for the first one)

I ran flutter clean, then flutter pub get, deleted Podfile.lock, ran pod install (in the ios folder) a bunch of times, but I still can't get the content to show in the webview on iOS (it works on Android), only blank white space where the html content is supposed to appear.

It's important to mention that I get my html from neither http nor https, but I load a String (which is html) and set it like this:

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

Is there maybe a way of tricking iOS to think that the html comes from https?


These are some common messages I see printed out in the console (not red, just regular color), and I only get these messages when running the app from android studio, not XCode (on a real iOS device):

[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}

and:

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

UPDATE: I found out, it also shows a blank/white page on iOS even when I use https, like _controller.loadRequest(Uri.parse('https://flutter.dev'));.

英文:

I got it to work on Android, the WebViewWidget displays correctly with the html content, no problem.

For iOS it just displays blank/white. I tried what I have seen suggested by people all over the internet, which is to add a few lines to Info.plist, that allow the WKWebView in iOS to load and display http (not secure, not only https):

&lt;key&gt;io.flutter.embedded_views_preview&lt;/key&gt;
&lt;string&gt;YES&lt;/string&gt;
&lt;key&gt;NSAppTransportSecurity&lt;/key&gt;
&lt;dict&gt;
  &lt;key&gt;NSAllowsArbitraryLoads&lt;/key&gt;
  &lt;true/&gt;
  &lt;key&gt;NSAllowsArbitraryLoadsInWebContent&lt;/key&gt;
  &lt;true/&gt;
&lt;/dict&gt;

(^^I don't really know what these lines individually do)
(^^I have also tried lowercase "yes" and &lt;true/&gt; as values for the first one)

I ran flutter clean, then flutter pub get, deleted Podfile.lock, ran pod install (in the ios folder) a bunch of times, but I still can't get the content to show in the webview on iOS (it works on Android), only blank white space where the html content is supposed to appear.

It's important to mention that I get my html from neither http nor https, but I load a String (which is html) and set it like this:

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

Is there maybe a way of tricking iOS to think that the html comes from https?


These are some common messages I see printed out in the console (not red, just regular color), and I only get these messages when running the app from android studio, not XCode (on a real iOS device):

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

and:

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

UPDATE: I found out, it also shows a blank/white page on iOS even when I use https, like _controller.loadRequest(Uri.parse(&#39;https://flutter.dev&#39;));.

答案1

得分: 4

我解决了这个问题,它出乎意料地与 http/https 无关... 请查看下面的代码注释以获取解释

_controller.setNavigationDelegate(
//...
  onNavigationRequest: (NavigationRequest request) {
    print('onNavigationRequest');
    //我最初有这一行来阻止通过href重定向到互联网上的任何地方
    //但这会阻止显示任何东西
    // return NavigationDecision.prevent;

    return NavigationDecision.navigate; //将其更改为此,现在可以工作了
  },
);

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

英文:

I solved the problem, it was unexpected and not related to http/https stuff... See the comments in below code for explanation

    _controller.setNavigationDelegate(
    //...
      onNavigationRequest: (NavigationRequest request) {
        print(&#39;onNavigationRequest&#39;);
        //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
      },
    );

I also removed all those lines from Info.plist, and it still works.

huangapple
  • 本文由 发表于 2023年2月16日 02:12:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75463878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定