I have created a NSURLRequest (HTTPS)
The delegate callbacks for the WKWebView come back with success, no error.
'decidePolicyForNavigationAction' is provided with the Allow Enum in the decision handler
@available(iOS 8.0, *)
func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
decisionHandler(.Allow)
}
and the didReceiveAuthChallenge is handled as such:
@available(iOS 8.0, *)
func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge,
completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
let cred = NSURLCredential.init(forTrust: challenge.protectionSpace.serverTrust!)
completionHandler(.UseCredential, cred)
print("Did receive auth challenge")
}
as i get no error after'didFinishNavigation'
I'm unsure whats going wrong as my WebView is still blank? If i use UIWebView i get the correct webpage showing?
Cheers,
To detect errors you should make sure you implement didFailNavigation:withError
and didFailProvisionalNavigation:withError
.
From the links that work, they seem to be https URLs. The one that does not is an http URL. Implementing the above error methods should tell you what is wrong.
There is a new security feature in iOS9 which fails to load HTTP URLs unless the server conforms to specific set of rules or you setup xcode to override the new feature. You can override the new feature by adding the following into your Info.plist file. Just paste the following at the bottom:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
This overrides all of the new functionality. You can however perform more specific overrides. The Apple tech note on the changes is here: https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html
I had this problem too but found this solution in a training video:
After that it worked here.
Make sure your WKWebView frame is set to a positive height in viewDidLoad, because otherwise the webview has no height and does not seem to resize itself after loading:
_webView =[[WKWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height )];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With