Tusker/Tusker/Extensions/URLSession+Development.swift

29 lines
897 B
Swift

//
// URLSession+Development.swift
// Tusker
//
// Created by Shadowfacts on 1/22/22.
// Copyright © 2022 Shadowfacts. All rights reserved.
//
import Foundation
extension URLSession {
#if targetEnvironment(simulator) && DEBUG
static let appDefault = URLSession(configuration: .default, delegate: Delegate(), delegateQueue: nil)
#else
static let appDefault = URLSession.shared
#endif
}
#if targetEnvironment(simulator) && DEBUG
private class Delegate: NSObject, URLSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
// allows testing with self-signed certificates in development
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
}
#endif