Using Swift and NSURLSession. The NSError localizedDescription I get is very generic when I don't have internet connection (manually turned off wifi/cell network). It says "The operation couldn’t be completed."
var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
I'm looking for a more specific message to send to the user. I enabled a breakpoint and inspected all objects but can't find anything good.
Prior to swift I was using AFNetworking with objective C:
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
The error messages I would get here were very descriptive, something like "the internet connection appears to be offline"
Swift 4
if let error = error as NSError?, error.domain == NSURLErrorDomain && error.code == NSURLErrorNotConnectedToInternet {
//not connected
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With