Post

Replies

Boosts

Views

Activity

Running NSURLSessionTask receives NSPOSIXErrorDomain Code=53 "Software caused connection abort" when app is relaunched from background
We have an app which issues a "poll request" to obtain data from a backend service. In certain scenarios, an app switch is performed, temporarily sending the user to another app where an action is performed, after which the user is sent back to our app.In iOS 11 the behaviour when our app is brought back from the background is, that we receive a NSURLErrorDomain Code=-1005 "Network connection lost" response, and therefore we re-issue our "poll request".In iOS 12 however, when the same scenario occurs, we receive the error.code -1005 only the first time. On subsequent returns from the app we switched to, iOS instead report NSPOSIXErrorDomain Code=53 "Software caused connection abort".The question is, if this is a bug in iOS 12, or an intended behaviour which we should handle somehow. In the latter case, is it possibly because we should configure our NSURLSessionTask differently, or should we simply accept the fact that we might have an error.code = 53 returned, and handle that like we would eg. an error.code = -1005 ?This is the code used for configuring/starting our NSURLSessionTask (the urlSession used basically is an [NSURLSessionConfiguration ephemeralSessionConfiguration] just with a couple of HTTPAdditionalHeaders set):+ (void)startRequest:(NSURLRequest *)request completion:(RequestCompletionHandler)completioHandler { __weak __typeof(self)weakSelf = self; NSURLSessionTask *sessionTask = [[JBRequestSession urlSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { if (error.code == NSURLErrorCancelled) { // Task was cancelled - Do not do anything return; } else { dispatch_async(dispatch_get_main_queue(), ^{ if (completioHandler) { completioHandler(nil, error); } }); return; } } NSHTTPURLResponse *httpURLResponse = (NSHTTPURLResponse*)response; [weakSelf saveCookiesForResponse:httpURLResponse]; NSDictionary *json = nil; if ([data length] > 0) { NSError *jsonError; json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; if (jsonError) { if (!error) { error = jsonError; } } } NSString *jsonPrint = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if ([weakSelf didGetServerErrorInResponse:httpURLResponse withOriginalBodyContent:jsonPrint andJson:json error:&error]) { // Server response error code if ([JBRequestSessionErrorHandler requestFailedWithSessionTimoutForResponse:response error:error]){ // Session time out - cancel all tasks [weakSelf cancelAllTasks]; } } dispatch_async(dispatch_get_main_queue(), ^{ if (completioHandler) { completioHandler(json, error); } }); }]; [sessionTask resume]; // Start request }
6
0
30k
Aug ’18