La prueba se realiza en iPhone 13 Pro 15.3.1, con Xcode 13.2.1. He reducido el problema de la siguiente manera dos pruebas. El siguiente código de prueba solo envía una simple solicitud https.
He permitido el acceso a la red para la aplicación de prueba tanto en Wifi como en celular. Y soy un desarrollador pagado.
Las siguientes dos pruebas se aprobaron en el simulador pero fallaron en el iPhone, por lo que significa que algo anda mal en el lado de mi iPhone, busque una publicación que diga que el iPhone de la marca China puede tener este problema, sigo investigando... orz
NSURLErrorNWPathKey=unsatisfied... 
El código de prueba se proporciona en el documento de Apple ( https://developer.apple.com/documentation/xctest/asynchronous_tests_and_expectations/testing_asynchronous_operations_with_expectations ).
func testDownloadWebData() { // Create an expectation for a background download task. let expectation = XCTestExpectation(description: "Download apple.com home page") // Create a URL for a web page to be downloaded. let url = URL(string: "https://apple.com")! // Create a background task to download the web page. let dataTask = URLSession.shared.dataTask(with: url) { (data, _, _) in // Make sure we downloaded some data. XCTAssertNotNil(data, "No data was downloaded.") // Fulfill the expectation to indicate that the background task has finished successfully. expectation.fulfill() } // Start the download task. dataTask.resume() // Wait until the expectation is fulfilled, with a timeout of 10 seconds. wait(for: [expectation], timeout: 10.0) }También pruebo mi versión, pero obtengo el mismo resultado.
func testDownloadWebData() { // Create an expectation for a background download task. let expectation = expectation(description: "Download apple.com home page") // Create a URL for a web page to be downloaded. let url = URL(string: "https://apple.com")! var request = URLRequest(url: url) request.httpMethod = "GET" let config = URLSessionConfiguration.default config.waitsForConnectivity = true let session = URLSession(configuration: config) // Create a background task to download the web page. let dataTask = session.dataTask(with: request) { (data, _, error) in // put a breakpoint here, no triggered. guard error == nil else { print(error!.localizedDescription) return } // Make sure we downloaded some data. XCTAssertNotNil(data, "No data was downloaded.") // Fulfill the expectation to indicate that the background task has finished successfully. expectation.fulfill() } // Start the download task. dataTask.resume() // Wait until the expectation is fulfilled, with a timeout of 10 seconds. wait(for: [expectation], timeout: 10.0) }