Iam working on Alarm application, I need to repeat a timer in background for every one minute to checke the fire date of Alarm,and when the alarm fired i need to play audio for 15 min
So for running timer in background i have written the bellow code,but it doesnot work, it is working upto 10 min background after that my app is terminating, please help me what i did wrong and how i should implement.
My code is:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//Making background task Asynchronous
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
__block UIBackgroundTaskIdentifier taskId = 0; taskId =
[application beginBackgroundTaskWithExpirationHandler:^
{
taskId = UIBackgroundTaskInvalid;
}];
if(self.callTimer)
{
if([self.callTimer isValid])
[self.callTimer invalidate];
self.callTimer = nil;
}
self.callTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(recall_timer) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.callTimer forMode:NSRunLoopCommonModes];
}
}