0

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 to http:// it works.
  • If I do not accept http and set the https:// in ConvertAPI URL it fails 3 times (3 logs about failed 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) 

enter image description here

aramusss
  • 2,391
  • 20
  • 30
  • 1
    There are other exceptions you can make for ATS to accept ciphers with lesser security and so on. You need to find out why the SSL handshake is failing - there should be a clue in the console. – Paulw11 Sep 20 '15 at 21:53
  • 1
    We have no problems using ConvertApi with SSL, please post full SSL Handshake exception to better understand the problem. – Tomas Sep 21 '15 at 10:40
  • Paulw11 & @Tomas thanks for the answer. I updated the question with more information. Please share the code (or solution) you are using SSL with iOS 9, if possible! – aramusss Sep 21 '15 at 17:06
  • 1
    This may help: http://stackoverflow.com/a/30748166/625521 – Jonas Sep 22 '15 at 13:01

0 Answers0