How can we make "https://..." work in Xcode Playground?

Working with Xcode playgrounds really help me figure things out by and for myself and make learning "new" (to me) concepts really "stick".


From what I gathered, primarily when using a Playground with asyncrhonous objects, the following statements should be at the beginning of the playground:

// The following will allow the use asynchronous code in playgrounds.
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely()


All is well and good, my code that involve the use of shared NSURLSession works (BTW, my app interfaces with api.themoviedb.org). Well... as long as I am using the unsecured URL (i.e., http://...).


It's quite a different story, though, when I start using secured URL (i.e., https://...). Using the latter gives me the following eror message when making the initial token request:

Error Domain=NSURLERrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be "api.themoviesb.org" which could put your confidential information at risk."  UserInfo=***(hidden on purpose - LETorres)***
{NSURLErrorFailingURLPeerTrustErrrKey=<SecTrustRef:0x7ff056107820>,
NSLocalizedRecoverySuggestion=Would youlike to connect to the serveranyway?,
_kCFStreamErrorCodeKey=-9807,NSUnderlyingError=0x7ff0560426d0 "The operation couldn't be completed. (kCFErrorDomainCFNetwork error -1202.)",
NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be "api.themoviedb.org" which could put your cpnfidential information at risk.,
NSErrorFailingURLKey=https://api.themoviedb.org/3/authentication/token/new?api_key=***(hidden on purpose - LETorres)***
....


Does anyone how to make "https://..." work in XCode Playground? is there any additional playground configuration that I am missing here?


(BTW, I know that the code using "https://..." work. My app works just fine with it. It is just the Xcode playground that is not playing nice with it at all.)


Any and all helpful hints will be truly appreaciated.


P.S. It would have been nice if this forum allows the uploading of screenshots. :-) If it were, I need not retype the text from my screenshot.

At first blush this looks like a straightforward server trust evaluation problem. Technote 2232 HTTPS Server Trust Evaluation covers this issue in detail.

However, when I tried to test the specific server you mentioned, HTTPS worked fine. Specifically, this playground:

import Cocoa
let d = NSData(contentsOfURL: NSURL(string: "https://api.themoviedb.org")!)
println(d?.length)

printed this result:

Optional(22936)

It could be that the server is doing different things for well-formed API queries, but it's hard for me to explore with the time I have available for helping out on DevForums.

P.S. It would have been nice if this forum allows the uploading of screenshots.

Quite. Rest assured that you're not the first person to ask for this (r. 22028729).

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
How can we make "https://..." work in Xcode Playground?
 
 
Q