NSURLSession / NSURLConnection Error loading HTTP on Swift 4

I have xcode 9.1 with fast 4 and I can no longer authenticate with webview. here is my code:

import UIKit protocol AuthViewControllerDelegate{ func getAccessToken(_ code: String) } class AuthViewController: UIViewController, NSURLConnectionDelegate { @IBOutlet weak var navItem: UINavigationItem! @IBOutlet weak var webView: UIWebView! var delegate: AuthViewControllerDelegate? override func viewDidLoad() { super.viewDidLoad() var link: "https://home.nest.com/login/oauth2?client_id=…" if let encodeURL = link.URLEncodedString(), let url = URL(string: encodeURL) { webView.loadRequest(URLRequest(url: url)) } } override var preferredStatusBarStyle : UIStatusBarStyle { return .lightContent } @IBAction func CancelPressed(_ sender: UIBarButtonItem) { self.dismiss(animated: true, completion: nil) } func webView(_ webView: UIWebView, shouldStartLoadWithRequest request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool { if let url = request.url?.absoluteString, url.contains("code=") { if let code = getQueryStringParameter(url,param: "code"){ self.dismiss(animated: true, completion: { () -> Void in UIApplication.shared.isNetworkActivityIndicatorVisible = false self.delegate?.getAccessToken(code) }) } } return true } func webViewDidStartLoad(_ webView: UIWebView){ UIApplication.shared.isNetworkActivityIndicatorVisible = true } func webViewDidFinishLoad(_ webView: UIWebView){ UIApplication.shared.isNetworkActivityIndicatorVisible = false } func getQueryStringParameter(_ url: String?, param: String) -> String? { if let url = url, let urlComponents = URLComponents(string: url), let queryItems = (urlComponents.queryItems) { return queryItems.filter({ (item) in item.name == param }).first?.value! } return nil } } 

And here is the error I get in the log:

2017-11-07 20: 49: 30.836087 + 0000 TestApp [1851: 1259046] TIC TCP Conn Error [32: 0x1c0365280]: 3: -9800 Err (-9800)

2017-11-07 20: 49: 30.836472 + 0000 TestApp [1851: 1259046] Error loading NSURLSession / NSURLConnection (kCFStreamErrorDomainSSL, -9800)

2017-11-07 20: 49: 30.836578 + 0000 TestApp [1851: 1259046] Task <0A675AA1-7110-4FCC-99B2-054380D22F01>. <0> Error loading HTTP (error code: -1200 [3: -9800])

2017-11-07 20: 49: 30.837548 + 0000 TestApp [1851: 1258708] NSURLConnection with error code -1200

And I already have this in my .plist file:

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

NB: the same code worked fine with fast 3.2

+5
source share
1 answer

Adding NSAllowsArbitraryLoads to .plist file resolves error

NSURLConnection Error - Code - 1200

where my development language is Objective C.

0
source

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


All Articles