Last active
June 8, 2018 17:03
-
-
Save shepting/829ff2f6940e71c0990c to your computer and use it in GitHub Desktop.
Xcode Playgrounds will fail network requests when Charles is running since ATS will fail. With an Xcode project you can update the Info.plist but Playgrounds don't have any such option. This is that option.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When using Charles, the network requests will always fail unless you can bypass ATS. | |
public class NetworkEnabler: NSObject, NSURLSessionDelegate { | |
public func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) { | |
completionHandler(.UseCredential, NSURLCredential(trust: challenge.protectionSpace.serverTrust!)) | |
} | |
} | |
// Then later when making a request: | |
let enabler = NetworkEnabler() | |
let session = NSURLSession(configuration: NSURLSession.sharedSession().configuration, delegate: enabler, delegateQueue: nil) | |
session.dataTaskWithRequest(request) {data,response,error in | |
// Code | |
}.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment