简体   繁体   中英

URLSession.dataTask is timing out on every request with Xcode 12.5 Beta 2

I upgraded to the latest Xcode 12.5 Beta 2 today, and now all of my URLSession.dataTask requests are failing and timing out. I create a sample project that makes a simple request, but it's failing each time. It works find with Xcode 12.5 Beta 1.

Here's a simple request:

guard let url = URL(string: "https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty") else { fatalError() }

let startTime = Date()

let task = URLSession.shared.dataTask(with: url) { data, response, error in
    let requestTime =  Date().timeIntervalSince(startTime)

    print("Time for request: \(requestTime)")

    if let error = error {
        updateLabel("requestTime: \(requestTime)\nError: \(error.localizedDescription)")
        return
    }
    guard let httpResponse = response as? HTTPURLResponse,
          (200...299).contains(httpResponse.statusCode) else {
        updateLabel("requestTime: \(requestTime)\n\(response.debugDescription)")
        return
    }
    if let mimeType = httpResponse.mimeType, mimeType == "text/html",
       let data = data,
       let string = String(data: data, encoding: .utf8) {
        DispatchQueue.main.async {
            print(string)
            //                    self.webView.loadHTMLString(string, baseURL: url)
        }
    }
}
task.resume()

func updateLabel(_ text: String) {
    print(text)
}

Is anyone else on the beta having this same issue?

Yes, I got the same Issue and Im struggling with it. It's seems there is nothing wrong with your code. Probably is some permission on xcode. Be sure to have added this line in info.plist enter image description here

This issue is resolved in Xcode 12.5 Beta 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM