英文:
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):
<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'));
.
答案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('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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论