WKWebView empty after "successful" HTTPS NSURLRequest

I created NSURLRequest (HTTPS)

Delegate callbacks for WKWebView return with success, with no errors.

'resolvePolicyForNavigationAction' is provided with an Allow enumeration in the solution handler

@available(iOS 8.0, *) func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) { decisionHandler(.Allow) } 

and didReceiveAuthChallenge is processed 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") } 

since I am not getting errors after 'didFinishNavigation' I am not sure what is going wrong, since my WebView is still empty? If I use UIWebView, do I get the correct webpage showing?

Greetings

+5
source share
3 answers

To detect errors, you need to make sure that you implement didFailNavigation:withError and didFailProvisionalNavigation:withError .

Of the links that work, they are apparently https addresses. One that is not an http url. Implementing the above error methods should tell you what is wrong.

IOS9 has a new security feature that does not load HTTP URLs if the server does not comply with a specific set of rules or you do not set xcode to override the new function. You can override the new function by adding the following to your Info.plist file. Just paste the following at the bottom:

 <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict> 

This redefines all new features. However, you can perform more specific overrides. Apple's technical note on the changes is here: https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html

+5
source

I also had this problem, but I found this solution in a tutorial video:

  • Add a dictionary key to your info.plist with the following name: NSAppTransportSecurity
  • Create a logical subkey named NSAllowsArbitraryLoads and set to TRUE.

After that he worked here.

+2
source

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 after loading:

 _webView =[[WKWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height )]; 
0
source

Source: https://habr.com/ru/post/1232265/


All Articles