Flutter: webview_flutter just displays blank (white) on iOS
Asked Answered
S

1

6

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'));.

Sliver answered 15/2, 2023 at 18:12 Comment(2)
Are you using a physical device or simulator?Generate
real device, iPhone 13 Pro with iOS 16.2Sliver
S
13

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('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
      },
    );

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

Sliver answered 19/2, 2023 at 7:10 Comment(3)
Having the same issue... what file is this?Benge
@Benge Its part of the setup when you create the controller. for example. controller = WebViewController(); controller.setNavigationDelegate(NavigationDelegate( onNavigationRequest: (change) => (NavigationDecision.navigate) ));Waverley
Same Issue I faced. And I also didn't add any of these to the Plist, and working fineVoiced

© 2022 - 2024 — McMap. All rights reserved.