The playground code at the bottom works as expected when the URL is
http://www.apple.com
and fails when the URL is
https://www.apple.com
NSURLErrorFailingURLPeerTrustErrorKey
I'm guessing that there is something wrong with sharedSession and https? Any suggestions?
// Playground - noun: a place where people can play
import Foundation
import XCPlayground
// allow the asynchronous task to continue, set timeout in console
XCPSetExecutionShouldContinueIndefinitely()
let plainURL = NSURL(string: "https://www.apple.com/")
var session = NSURLSession.sharedSession()
func firstHandler(data:NSData!, response:NSURLResponse!, error: NSError!) {
if let err = error {
println("WTF error: \(error), \(error.userInfo)")
}
else {
println("No error!")
print(NSString(data: data, encoding: NSUTF8StringEncoding)!)
}
}
var plainTask:NSURLSessionDataTask = session.dataTaskWithURL(plainURL!, completionHandler: firstHandler)
plainTask.resume()