要支持HTTP请求:您需要禁用Apple Transport Security(ATS)功能。有两种选择:
<key>NSAppTransportSecurity</key>
<key>NSExceptionDomains</key>
<key>www.yourserver.com</key>
<!-- add this key to enable subdomains such as sub.yourserver.com -->
<key>NSIncludesSubdomains</key>
<true/>
<!-- add this key to allow standard HTTP requests, thus negating the ATS -->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!-- add this key to specify the minimum TLS version to accept -->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
<key>NSAppTransportSecurity</key>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
其他 Info.plist 属性:
NSAllowsLocalNetworking
: 设置为
true
以支持加载本地网络资源 (
Official wiki
)
NSAllowsArbitraryLoadsInWebContent
: 针对从webview发出的网络请求 (
Official wiki
)
支持http网络 官方文档
要支持所有的http请求, 需要在
res/xml/network_security_config.xml
配置如下代码:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
然后打开
AndroidManifest.xml
, 根据如下代码进行配置:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
</application>
</manifest>
在 Android 端, 如果需要支持
<input type="file" accept="image/*" capture>
HTML标签, 则需在
android/app/src/main/AndroidManifest.xml
文件的
<application>
标签中配置如下:
<provider
android:name="com.pichillilorenzo.flutter_inappwebview.InAppWebViewFileProvider"
android:authorities="${applicationId}.flutter_inappwebview.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
更多其他的配置, 请参考 flutter_inappwebview
🔨 使用
import 'package:fk_webview/fk_webview.dart';
FKWebView(
initialUrl: 'yoururl',
initialData: '<html><body><h1>test</h1></body></html>',
initialFile: 'assets/html/index.html', config: FKWebViewConfig());
Refer to the Changelog to get all release notes.