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
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>flightplanning.navcanada.ca</key>
<dict/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
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 <AB92C36B-6E8A-42E5-9C3E-73AF6E258F43>.<0> HTTP load failed (error code: -1200 [3:-9824])
NSURLConnection finished with error - code -1200
Any corrective suggestions would be greatly appreciated.
Note when I use the same code to load web content from other web sites it seems to work ok.
When I access this website, https://flightplanning.navcanada.ca/cgi-bin/Fore-obs/notam.cgi?ni_FIR=on&Stations=CZEG, on Safari, it loads the web site with no problems.