Swift 4: Errors When Loading Web Page Content in iOS app

The app I’m creating in Xcode 9 needs to load web page content, so I followed the code suggested in https://www.hackingwithswift.com/example-code/strings/how-to-load-a-string-from-a-website-url

 

if let url = URL(string: "https://flightplanning.navcanada.ca/cgi-bin/Fore-obs/notam.cgi?ni_FIR=on&Stations=CZEG") {
    do {
        let contents = try String(contentsOf: url)
        print(contents)
    } catch {
        // contents could not be loaded
    }
} else {
    // the URL was bad!
}

 

From various other threads, it seemed to be a problem with the info.plist file, so following these suggestions I added the following entries in the info.plist:

https://i.stack.imgur.com/LYuv4.png

 

NSAppTransportSecurity

  NSAllowsArbitraryLoads

 

  NSExceptionDomains

 

  flightplanning.navcanada.ca

 

  NSTemporaryExceptionAllowsInsecureHTTPLoads

 

  NSIncludesSubdomains

 

 

 

 

The errors returned:

SSL_ERROR_SSL(1): operation failed within the library

SSLV3_ALERT_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl_Sim/boringssl-109.50.14/ssl/tls_record.c:547:SSL alert number 40

HANDSHAKE_FAILURE_ON_CLIENT_HELLO

Function boringssl_context_get_os_status: line 4268 SSL_AD_HANDSHAKE_FAILURE

TIC TCP Conn Failed

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824)

Task .<0> HTTP load failed (error code: -1200 [3:-9824])

NSURLConnection finished with error – code -1200

 

Any corrective suggestions would be greatly appreciated.

Powered by WPeMatico

About

You may also like...

Comments are closed.