title: UILocalNotification does not fire after 10 minutes in background
body: <p>I have a VoIP application. Which is working fine. Call is working in foreground and background.</p>
  
  <p><strong>Following steps are done:</strong></p>
  
  <ol>
  <li><p>UIBackgroundModes => voip in Info.plist</p></li>
  <li><p>Configured one of the app’s sockets for VoIP usage.</p></li>
  <li><p>Before moving to the background, setKeepAliveTimeout:handler: is called</p></li>
  <li><p>Configured audio session to handle transitions to and from active use.</p></li>
  <li><p>To ensure a better user experience on iPhone, used the Core Telephony framework to adjust behavior in relation to cell-based phone calls;</p></li>
  <li><p>To ensure good performance for VoIP app, used the System Configuration framework to detect network changes and allow app to sleep as much as possible.</p></li>
  </ol>
  
  <p><strong>Now the thing is when application is in background and a call comes then UILocalNotification fires for the following. And user can see a notification with two buttons CANCEL and RECEIVE</strong></p>
  
  <pre><code>- (void)applicationDidEnterBackground:(UIApplication *)application
  {
      bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
          [application endBackgroundTask: bgTask];
          bgTask = UIBackgroundTaskInvalid;
      }];
  
      dispatch_async(dispatch_get_main_queue(), ^{
          while ([application backgroundTimeRemaining] &gt; 1.0) {
              NSString *friend = [self checkForIncomingChat];
              if ([friend length]&gt;0) {
                  [[UIApplication sharedApplication] cancelAllLocalNotifications];
                  UILocalNotification *localNotif = [[UILocalNotification alloc] init];
                  if (localNotif) {
                      localNotif.alertBody = [NSString stringWithFormat: NSLocalizedString(@"%@", nil), friend];
                      localNotif.alertAction = NSLocalizedString(@"Receive", nil);
                      localNotif.soundName = @"alarmsound.caf";
                      localNotif.applicationIconBadgeNumber = 1;
                      [application presentLocalNotificationNow:localNotif];
                      friend = nil;
                  }
              }
              sleep(1);
          }
          [application endBackgroundTask:self-&gt;bgTask];
          self-&gt;bgTask = UIBackgroundTaskInvalid;
      });
   }
  
   - (NSString *) checkForIncomingChat {
  
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
      NSString *incall = [prefs objectForKey:@"incall"];
      if ([incall length]&gt;0) {
          [prefs setObject:@"" forKey:@"incall"];
          return incall;
      }
      return @"";
  };
  </code></pre>
  
  <p><strong>Now the problem is:</strong> </p>
  
  <p>After going to the background by pressing home button application fires UILocalNotification if any call comes within 10 minutes. </p>
  
  <p>After 10 minutes if any call comes it is running in the background. UILocalNotification does not fire, so user can not know anything.</p>
  
  <p>It happens because background task stops after 10 minutes.</p>
  
  <p>How can I manage it or extend background task for long running or restart background task. </p>
  
  <p>More and more answer I have found after searching but nothing works for long running background task.</p>
  
  <p>Please anybody help me. I am trying it since 2 weeks. </p>