Call made like this
let jsonData = try JSONSerialization.data(withJSONObject: requestBody)
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData
let (data, response) = try await URLSession.shared.data(for: request)
When I call it from the simulator it works perfect 100% of the time.
When I run it on the phone while on WiFi it works perfect 100% of the time.
BUT when I run it on the phone on cell network. It fails randomly.
But if I try to call that end point using another API test app on the phone. It works.
The error I get back when it fails as follows:
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=57, NSUnderlyingError=0x28198df50 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x2833f6e20 [0x1e1c79d10]>{length = 28, capacity = 28, bytes = 0x1c1e01bb000000002606470000200000 ... 681a00aa00000000}, _kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask .<2>" ), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://blahblah/v1/run, NSErrorFailingURLKey=https://blahblah/v1/run, _kCFStreamErrorDomainKey=1}