Created
January 23, 2022 19:54
-
-
Save backslash-f/66c9bdd40e7dc56d7d376299df3dc7c9 to your computer and use it in GitHub Desktop.
Charles + Swift Playgrounds
This file contains hidden or 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
// "Charles Enabler" | |
// https://stackoverflow.com/a/57253011/584548 | |
public class NetworkEnabler: NSObject, URLSessionDelegate { | |
public func urlSession(_ session: URLSession, | |
didReceive challenge: URLAuthenticationChallenge, | |
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { | |
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!)) | |
} | |
} | |
// Then, when creating a URLSession instance: | |
let urlSession = URLSession(configuration: .default, delegate: NetworkEnabler(), delegateQueue: nil) | |
// Create a request and finally... | |
let (data, response) = try await urlSession.data(for: request) | |
// Profit 💰 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment