I have a voip application.
I am using UILocalNotification
in my application to alert notification for incoming call when application in background.
Try This :
- (void)applicationDidEnterBackground:(UIApplication *)application
{
__block UIBackgroundTaskIdentifier bgTask ;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
pollingTimer2 = [NSTimer scheduledTimerWithTimeInterval:4.0f target:self selector:@selector(process) userInfo:nil repeats:YES];
}
-(void) process
{
[self didLocalNotification];
}
-(void)didLocalNotification
{
[[UIApplication sharedApplication]cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
{
return;
}
NSLog(@"calling didLocalNotification");
localNotification.applicationIconBadgeNumber =0;
localNotification.alertBody =@"Message!";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}