Network errors returned by NSURLSession have no localized description
| Originator: | nicolas.bouilleaud | ||
| Number: | rdar://18176157 | Date Originated: | 2014-09-30 |
| Status: | Resolved | Resolved: | 2015-02-12 |
| Product: | iOS SDK | Product Version: | 8.0 |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
On iOS8 (beta 5), NSURLSession returns errors that have no "NSLocalizedDescription". This is not the case with NSURLConnection, and it is new to iOS7.
Steps to Reproduce:
See attached minimal sample project. Here's the relevant code section:
```
// Create a failing request
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://nonexistingdomain.tld"]];
// Load it with NSURLConnection
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
printf("NSURLConnection: %s(%d) %s\n", error.domain.UTF8String, (int)error.code, error.localizedDescription.UTF8String);
// On iOS7.1: NSURLConnection: NSURLErrorDomain(-1009) The Internet connection appears to be offline.
// On iOS8b5: NSURLConnection: NSURLErrorDomain(-1009) The Internet connection appears to be offline.
}];
// Load it with NSURLSession
[[[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]
dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
printf("NSURLSession: %s(%d) %s\n", error.domain.UTF8String, (int)error.code, error.localizedDescription.UTF8String);
// On iOS7.1: NSURLSession: NSURLErrorDomain(-1009) The Internet connection appears to be offline.
// On iOS8b5: NSURLSession: NSURLErrorDomain(-1009) The operation couldn’t be completed. (NSURLErrorDomain error -1009.)
}] resume];
```
Expected Results:
The returned NSError should have a localized description, and be user-displayable.
Actual Results:
The returned NSError has no userInfo at all, just a domain and a code.
This is only happening when using NSURLSession on iOS8. On iOS7, NSURLSession is returning a displayable NSError, and NSURLConnection is working fine both on iOS7 and iOS8.
Version:
iOS8b5
Notes:
Configuration:
Xcode6b6, iPhone Simulator
Attachments:
'NetworkErrorDescriptionTest.zip' was successfully uploaded.
http://cl.ly/2i2y2r38010G/download/NetworkErrorDescriptionTest.zip
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!