I am trying to get an image using ConvertApi to get an image from a webpage URL. My problem is that iOS >9 requires SSL for connections, and even ConvertAPI gives us https URLs, the SSL Handshake
keeps failing. Here's my code to get the image:
let stringData = "ApiKey=\(ConvertAPI.Key)&CUrl=\(anURL.absoluteString)";
let request = NSMutableURLRequest(URL: NSURL(string: ConvertAPI.URL)!)
request.HTTPMethod = "POST"
request.HTTPBody = stringData.dataUsingEncoding(NSUTF8StringEncoding)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
let returnImage = UIImage(data: data!)
})
Please note that:
- If I do accept
http
(using info.plist method) and change the ConvertAPI URL tohttp://
it works. - If I do not accept
http
and set thehttps://
in ConvertAPI URL it fails 3 times (3 logs aboutfailed ssl handshake
and then returns an error. - Swift 2, Xcode 7.1
Is this a ConvertAPI SSL problem? Is this my code problem? or is this a Swift bug?
EDIT This is the console log for error and object taken with a breakpoint:
2015-09-21 19:02:12.386 appname[14528:606252] CFNetwork SSLHandshake failed (-9801)
2015-09-21 19:02:12.387 appname[14528:606252] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9801)