在我们开发过程中经常会碰到直接访问开发人员的私有地址, 这样在app 上是无法打开指定的网页的。

   在iOS中需要对WKWebView 进行如下设置:

1、在工程的Plist 文件中添加一下选项

   App Transport Security Settings -> Allow Arbitrary Loads in Web Content  设置为YES ,如下图

iOS  Webview打开不受信的URL

 

2、 WKWebView 指定的代理类中,实现协议WKNavigationDelegate

- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
}
}

 

  通过以上方法本人已经验证可以跳转私有IP地址Web。

 

相关文章:

  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
猜你喜欢
  • 2022-01-01
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
相关资源
相似解决方案