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。
?
轉載于:https://www.cnblogs.com/kingbo/p/8576134.html
總結
以上是生活随笔為你收集整理的iOS Webview打开不受信的URL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电影【楚门的世界】有现实原型么?是谁呢?
- 下一篇: NOIP2005普及组第4题 循环