I am also getting this on the watchOS 6 beta 2 simulator.
On a Series 3 GPS + watchOS 6 beta 2 it works fine.
Invocation:
let quickSession = URLSession(configuration: .default)
var dataTask:URLSessionDataTask?
if var urlComponents = URLComponents(string: "<URL HERE>") {
guard let url = urlComponents.url else { return }
dataTask = quickSession.dataTask(with: url) { data, response, error in
defer { dataTask = nil }
if let error = error {
errorMessage += "DataTask error: " + error.localizedDescription + "\n"
} else if let data = data,
let response = response as? HTTPURLResponse,
response.statusCode == 200 {
if let array = try? JSONDecoder.init().decode([Model].self, from: data) {
print(array)
list = array
}
}
}
dataTask?.resume()
}
Output:
2019-06-19 07:10:25.016688-0700 iAlert WatchKit Extension[12983:182860] Task <32144E5C-6D9B-43D6-99EF-A8338DA2D0F4>.<1> finished with error [-997] Error Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <32144E5C-6D9B-43D6-99EF-A8338DA2D0F4>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <32144E5C-6D9B-43D6-99EF-A8338DA2D0F4>.<1>, NSLocalizedDescription=Lost connection to background transfer service}
It's worth noting when I switched to my device, to run the watchOS simulator an iOS simulator had been launched in the background, but no UI was loaded as far as I could tell.
I bring that up because in this note about installing root certs for ATS, the watchOS simulator has a note that reads:
The watchOS simulator always runs network requests via the paired iPhone simulator, so installing a CA’s root certificate on that paired simulator is sufficient to support watchOS testing.
So possibly this is related to the iOS simulator being in some backgrounded state?