flutter开发时,ios通过xcode打包ipa包,打开https页面白屏,因为无法usb调试,所以就只能猜问题原因,想到的是证书信任的问题,就去网上找方法,找到一篇有用的文章 这里
但是ios方面的只有解决办法,没有说明放到哪里,走了不少弯路。
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
NSURLCredential * card = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
}
}
这个方法要放在下面的目录下(说明一下:我使用的webview是1.0.7版本,所以根据你使用的版本去切换路径)
flutter223\flutter.pub-cache\hosted\pub.flutter-io.cn\webview_flutter-1.0.7\ios\Classes
放在这个文件里
FLTWKNavigationDelegate.m
代码是这样子的
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
NSError *contentProcessTerminatedError =
[[NSError alloc] initWithDomain:WKErrorDomain
code:WKErrorWebContentProcessTerminated
userInfo:nil];
[self onWebResourceError:contentProcessTerminatedError];
}
//如果需要证书验证,与使用AFN进行HTTPS证书验证是一样的(方法放在最下面了)
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
NSURLCredential * card = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
}
}
@end
到这里重新打包,就成功解决https白屏的问题了

本文介绍了解决Flutter开发中iOS设备访问HTTPS页面出现白屏的问题。通过在特定目录下的FLTWKNavigationDelegate.m文件中添加代码实现证书验证,确保WKWebView能够正确加载HTTPS资源。
3936

被折叠的 条评论
为什么被折叠?



