Skip to content

Instantly share code, notes, and snippets.

@NghiaTranUIT
Created January 31, 2020 02:28
Show Gist options
  • Save NghiaTranUIT/275c8da5068d506869a21bd16da27094 to your computer and use it in GitHub Desktop.
Save NghiaTranUIT/275c8da5068d506869a21bd16da27094 to your computer and use it in GitHub Desktop.
A workaround to enable SSL Proxying on iOS Swift Playground for Charles and Proxyman app. (swift 5)
// This workaround is only for iOS Swift Playground
// Don't need it on macOS Playground
import Foundation
// Accept all challenges from Charles or Proxyman for self-signed certificates
class NetworkSSlProxying: NSObject, URLSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
}
// Init session
let delegate = NetworkSSlProxying()
let conf = URLSessionConfiguration.default
let session = URLSession(configuration: conf, delegate: delegate, delegateQueue: nil)
// Request
let url = URL(string: "https://google.com")!
let task = session.dataTask(with: url) { (data, response, error) in
print(response)
}
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment