title: Freezing http requests in background state
body: <p>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 </p>
  
  <pre><code>Error Domain=kCFErrorDomainCFNetwork Code=-1001 "The request timed out.
  </code></pre>
  
  <p>App use last AFNetworking 3.1.0 at this moment, and BFTask helper. </p>
  
  <p>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:</p>
  
  <pre><code>&gt; 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></pre>
  
  <p>code: </p>
  
  <pre><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);
                  }
              }];
  </code></pre>
  
  <p>after some period of time user launch app, and this code trying to continue executing, and we have error with timeout.</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>The difference in time about 16 minutes, when user launch app again.
  And this can be in another part of http queries</p>
  
  <p>The question is, why iOS freeze queries in background, and how to fix this.</p>