终于得到了答案:
第 1 步 >> import SafariServices
第 2 步 >> 将 NSURLConnectionDelegate 与您的 ViewController 一起使用,即
class ViewController:UIViewController, NSURLConnectionDelegate
第 3 步 >> 覆盖方法:
func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace?) -> Bool
func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge)
第 4 步 >> GOTO viewDidLoad 在 Web 视图中加载 URL 的位置,并进行更改:
let url = NSURL (string: URL)//where URL = https://203.xxx.xxx.xxx
let requestObj = NSURLRequest(URL: url!)
var request: NSURLRequest = NSURLRequest(URL: url!)
var connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: false)!
connection.start()
YOUR_WEBVIEW.loadRequest(requestObj);
第 5 步 >> 使用 shouldStartLoadWithRequest 转到 webView 并返回 true。如果你返回 false,你永远不会得到结果。
func webView(IciciWebView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool
{
//Do whatever you want to do.
return true
}
第 6 步 >> 更新函数:
func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace?) -> Bool
{
print("In canAuthenticateAgainstProtectionSpace");
return true;
}
第 7 步 >> 更新函数:
func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge)
{
print("In willSendRequestForAuthenticationChallenge..");
challenge.sender!.useCredential(NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!), forAuthenticationChallenge: challenge)
challenge.sender!.continueWithoutCredentialForAuthenticationChallenge(challenge)
}
参考资料:Swift 的开发者参考资料、Stackoverflow 的 Lot of Pages 以及 Google 的一些论坛。
这些步骤解决了我的问题,现在我可以在 Web 视图中加载自签名 URL。