Ced*_*ric 3 webview ios wkwebview flutter webview-flutter
我让它在 Android 上工作,WebViewWidget正确显示 html 内容,没有问题。
对于 iOS,它仅显示空白/白色。我尝试了网上人们建议的方法,即在 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>
Run Code Online (Sandbox Code Playgroud)
(^^我真的不知道这些行各自的作用)
(^^我也尝试过小写“ yes”并<true/>作为第一行的值)
我跑了flutter clean,然后flutter pub get删除了 Podfile.lock,跑了pod install很多次(在 ios 文件夹中),但我仍然无法在 iOS 上的 webview 中显示内容(它适用于 Android),只有空白区域html 内容应该出现。
值得一提的是,我既不从 http 也不从 https 获取 html,但我加载一个字符串(即 html)并将其设置如下:
String text = ...
await _controller.loadHtmlString(text);
Run Code Online (Sandbox Code Playgroud)
有没有办法欺骗 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}
Run Code Online (Sandbox Code Playgroud)
和:
Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
Run Code Online (Sandbox Code Playgroud)
更新:我发现,即使我使用 https,例如_controller.loadRequest(Uri.parse('https://flutter.dev'));.
我解决了这个问题,这是意想不到的,与 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
},
);
Run Code Online (Sandbox Code Playgroud)
我还删除了所有这些行Info.plist,它仍然有效。
| 归档时间: |
|
| 查看次数: |
3234 次 |
| 最近记录: |