There app have many tasks when app in background state, basically work with bluetooth dongles, and receive/sending data to server. Sometimes when app in background state send a query, system is "freeze in" this query. And after launch app, system is "freeze out", and we have
Error Domain=kCFErrorDomainCFNetwork Code=-1001 "The request timed out.
App use last AFNetworking 3.1.0 at this moment, and BFTask helper.
For more detail. Imagine, user use app for some reason, after app goes app to background state (user press home button or lock device), app normally continue working at background state. System or user can kill the app. App can wake up after some user interaction (via geolocation services, geofencing) at wake up moment, app is restarting, and send query to sever, with checking user (authorization, gets new token etc). At this moment we can see in the logs:
> Request method: POST url: https://******/v1/account/token headers: {
UserName = "***@***.com";
"grant_type" = password;
password = ****
} at time: 2016-08-15 15:30:45 +0000
code:
if ([request.method isEqualToString:@"GET"]) {
return [manager GET:request.url parameters:request.params progress:nil success:^(NSURLSessionTask *operation, id responseObject) {
} failure:^(NSURLSessionTask *operation, NSError *error) {
processError(operation, error);
}
}];
after some period of time user launch app, and this code trying to continue executing, and we have error with timeout.
error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x156d8ce10
{Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)"
UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=https://******/v1/account/token, NSErrorFailingURLKey=https://******/v1/account/token, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}
at time: 2016-08-15 15:46:28 +0000
The difference in time about 16 minutes, when user launch app again. And this can be in another part of http queries
The question is, why iOS freeze queries in background, and how to fix this.