1

I had created app which is not working with iOS 9.

import UIKit

    class WebViewController: UIViewController, UIWebViewDelegate {

        @IBOutlet var webView: UIWebView!
        override func viewDidLoad()
        {
            super.viewDidLoad()
            // Do any additional setup after loading the view.

            let requestURL = NSURL(string:"http://stackoverflow.com")
            let request = NSURLRequest(URL: requestURL!)
            webView.loadRequest(request)

            webView.delegate = self

        }

        override func didReceiveMemoryWarning()
        {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }

        func webViewDidStartLoad(webView: UIWebView)
        {
            print("Load started")
            UIApplication.sharedApplication().networkActivityIndicatorVisible = true
        }
        func webViewDidFinishLoad(webView: UIWebView)
        {
            print("Load finished")
            UIApplication .sharedApplication().networkActivityIndicatorVisible = false

        }
        func webView(webView: UIWebView, didFailLoadWithError error: NSError?)
        {
            print("Error = ", error)
        }
        func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool
        {
            print("URl ", request.URL?.absoluteString)
            return true
        }
    }

Showing this message.

2015-10-20 14:46:29.976 WebViewDemo[2802:84627] Loading URL :https://stackoverflow.com/ 2015-10-20 14:46:30.041 WebViewDemo[2802:84745] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2015-10-20 14:46:30.160 WebViewDemo[2802:84627] Failed to load with error :Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x7fedabe113b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=https://stackoverflow.com/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLKey=https://stackoverflow.com/}}, NSErrorFailingURLStringKey=https://stackoverflow.com/, NSErrorFailingURLKey=https://stackoverflow.com/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

Community
  • 1
  • 1
Aarti Oza
  • 1,134
  • 2
  • 14
  • 31
  • In IOS 9 Nd Later we need to add NSAppTransportSecurity in Info.Plist Open Info.Plist As source code and copy and paste this at the end. NSAppTransportSecurity NSAllowsArbitraryLoads – Uma Madhavi Oct 20 '15 at 10:12
  • I wouldn't say this *needs* to be done. Ideally you should try and use secure connections where possible. i.e. HTTPS rather than HTTP. – Matt Le Fleur Oct 20 '15 at 10:45
  • Also is the same code that caused this error? Because the error is throwing up an error loading Stack Overflow, not Google as in your code. So for this example (based on your error) use `https://stackoverflow.com` since Stack Overflow does support HTTPS connections. – Matt Le Fleur Oct 20 '15 at 10:46

2 Answers2

2

You have to add this in your .plist file

  1. Add a NSAppTransportSecurity : Dictionary.
  2. Add Subkey named : NSAllowsArbitraryLoads as Boolean : YES

enter image description here

Hopefully this will help you.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
Avinash651
  • 1,399
  • 11
  • 17
0

Set the NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your .plist file. If NSAppTransportSecurity not exist manually write it.

enter image description here

Aarti Oza
  • 1,134
  • 2
  • 14
  • 31