I have an application that uses iOS, todayExtension and watchOS as targets.
Until the launch of the new iOS 13, everything was working fine, that week I downloaded the iOS 13 beta on my iPhone and the watchOS 6 on my watch. Then, suddenly my app stopped working on the watch. When I put it on debug, I saw that none of my URLSession requests were being completed. Did something huge changed?
class func verifyInternet(errorHandler:@escaping (String) -> (), completionHandler:@escaping (JSON) -> ()) {
let myUrl = URL(string: "https://google.com/")
var request = URLRequest(url:myUrl!)
request.httpMethod = "GET";
request.httpBody = nil
request.cachePolicy = URLRequest.CachePolicy.reloadIgnoringLocalCacheData
let task = URLSession.shared.dataTask(with: request as URLRequest, completionHandler: {
data, response, error in
if error != nil
{
errorHandler(error.debugDescription)
return
}
if response.debugDescription.contains("Status Code: 200") {
completionHandler("connection ok")
return
}
if response != nil, let jsonString = JSON(parseJSON: response!.description) as? JSON {
//convert the JSON to raw NSData
do {
let json = try jsonString //JSON(data: dataFromString)
if json.dictionary?.keys.first?.contains("error") ?? false {
errorHandler(json.dictionary?.values.first?.stringValue ?? "error")
}
completionHandler(json)
} catch {
print("Error \(error)")
}
}
})
task.resume()
}
This is actually some of my code that on OS 5 worked nicely and on OS 6 (Simulator and Watch) doesn't (I already tried marking the option "Run independent from iPhone" also). I would paste here the error I'm getting but when I run my code on Watch simulator the debugger isn't printing anything :).
After a lot of debugging, I've noticed that you're supposed to check the "Supports Running Without iOS App Installation" checkbox under Project > Watch Extension > General > Deployment Info. On Xcode beta, the watch simulator never boots with the cellphone simulator as it did on Xcode 10.3. If you don't check that box, the watch will never have internet connection, as it depends on a cellphone that isn't there.
I hope other users find the information useful!