title: iOS background fetch before termination
body: <p>I have a situation where I must call a web service before app termination but not when enters the background, because this should be done only once which when the app get terminated.</p>
  
  <p>I tried the background execution thing but I believe it won't work once the app get terminated but only if the app in the background.</p>
  
  <p>Here is my latest try inside <code>applicationWillTerminate:</code></p>
  
  <pre><code>__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{
          [application endBackgroundTask:bgTask];
          bgTask = UIBackgroundTaskInvalid;
      }];
  
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
          // Call web service here 
          [application endBackgroundTask:bgTask];
          bgTask =UIBackgroundTaskInvalid;
      });
  </code></pre>