Cancelling NSURLSessionDataTask in iOS 11 logs error -999.

Is it possible to prevent iOS 11 to log -999(NSURLErrorCancelled) error when NSURLSessionDataTask was cancelled?

iOS11, Xcode 9.

CODE:


- (void)testURLSession{
    NSURLSession *urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    NSURLSessionDataTask *dataTask;
    NSString *requestUrl = @"https://www.apple.com/";
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestUrl]];
    for (NSInteger i = 0; i < 3 ; i++) {
        if (dataTask) {
            [dataTask cancel];
            dataTask = nil;
        }
        dataTask = [urlSession dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
            if ([error code] == NSURLErrorCancelled) {
                NSLog(@"Cancelled");
            }
        }];
        [dataTask resume];
    }
}

OUTPUT:

Cancelled
Cancelled
Task <65AA792B-CFDC-4C60-AAD1-681A861BE353>.<1> finished with error - code: -999
Task <6B4808BC-3911-44D7-B1D6-C5BDFC2881B3>.<2> finished with error - code: -999

Replies

Is it possible to prevent iOS 11 to log -999 (NSURLErrorCancelled) error when NSURLSessionDataTask was cancelled?

Probably not. Why does this matter to you?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

We distribute SDK and it looks like our SDK error rather than iOS. I guess once error is handled, iOS should not log such message. Please note, it was introduced in iOS 11

OK then. As always, if something like this is causing you grief you should file a bug about it.

By way of explanation, back in iOS 10 we introduced a new logging system-wide logging architecture (watch WWDC 2016 Session 721 Unified Logging and Activity Tracing for the details) and lots of subsystem, including CFNetwork, are in the process of moving over to that. Until that move is fully finished you’re going to encounter some weird edge cases like this one.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"