zoukankan      html  css  js  c++  java
  • iOS Webview打开不受信的URL

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

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

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

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

    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。

  • 相关阅读:
    141. Linked List Cycle【easy】
    237. Delete Node in a Linked List【easy】
    234. Palindrome Linked List【easy】
    排序_归并排序
    排序_选择排序
    排序_快速排序
    排序_冒泡排序
    排序_希尔排序
    排序_插入排序
    121. Best Time to Buy and Sell Stock【easy】
  • 原文地址:https://www.cnblogs.com/kingbo/p/8576134.html
Copyright © 2011-2022 走看看