3 Replies
      Latest reply on Sep 27, 2017 1:09 AM by eskimo
      dashchak Level 1 Level 1 (0 points)

        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