feat!(ios): remove native dependency promises (#3631)
This commit is contained in:
24
ios/Video/Features/URLSession+data.swift
Normal file
24
ios/Video/Features/URLSession+data.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import Foundation
|
||||
|
||||
@available(iOS, deprecated: 15.0, message: "Use the built-in API instead")
|
||||
@available(tvOS, deprecated: 15.0, message: "Use the built-in API instead")
|
||||
extension URLSession {
|
||||
func data(from request: URLRequest) async throws -> (Data, URLResponse) {
|
||||
if #available(iOS 15, tvOS 15, *) {
|
||||
return try await URLSession.shared.data(for: request)
|
||||
} else {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
let task = self.dataTask(with: request, completionHandler: { data, response, error in
|
||||
guard let data, let response else {
|
||||
let error = error ?? URLError(.badServerResponse)
|
||||
return continuation.resume(throwing: error)
|
||||
}
|
||||
|
||||
continuation.resume(returning: (data, response))
|
||||
})
|
||||
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user