我想在 iOS 模拟器上访问公司内部 https 的页面。这个页面可以在 safari 上访问。但是 WKWebView 无法访问。程序说以下错误。
An SSL error has occurred and a secure connection to the server cannot be made.
TLS 版本为 TLSv1.2。
如果我设置 NSAllowsArbitraryLoads,我可以访问。但我认为这种方式并不好。
我的代码如下。
//
// ViewController.swift
// TestClient
//
// Created by 平塚 俊輔 on 2015/12/07.
// Copyright © 2015年 平塚 俊輔. All rights reserved.
//
//1.WebKit Frameworkをimportする
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
//2.WKWebviewの宣言!
var _webkitview: WKWebView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//3.WebKitのインスタンス作成!
self._webkitview = WKWebView()
//4.ここでWebKitをviewに紐付け
self.view = self._webkitview!
self._webkitview!.navigationDelegate = self
//5.URL作って、表示させる!
var url = NSURL(string:"https:/******")
var req = NSURLRequest(URL:url!)
self._webkitview!.loadRequest(req)
}
// MARK: WKNavigationDelegate
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
NSLog("Start")
}
func webView(webView: WKWebView!, didFailNavigation navigation: WKNavigation!, withError error: NSError!) {
NSLog("Failed Navigation %@", error.localizedDescription)
}
func webView(webView: WKWebView!, didFinishNavigation navigation: WKNavigation!) {
// Finish navigation
NSLog("Finish Navigation")
NSLog("Title:%@ URL:%@", webView.title!, webView.URL!)
// Run Javascript(For local)
// webView.evaluateJavaScript("var el=document.getElementById('user');el.style.backgroundColor='yellow';", nil)
}
func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
print(error)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
这是什么问题?
顺便说一句,我可以在真实设备上访问。我无法仅在模拟器上访问。