I am working with iphone background process in my application. it is running in background but after 10 min it is terminating my application. And not working for long time.
My application contains 1 counter with timmer when viewdidload at that time my counter will start and when i will click on home button it will run in the background. In background it is running perfect but after 10 min it is stoping my background process. Following is my code for it.
in .h file.
IBOutlet UILabel *thecount;
int count;
NSTimer *theTimer;
UIBackgroundTaskIdentifier counterTask;
in my .m
- (void)viewDidLoad {
UIBackgroundTaskIdentifier bgTask = nil;
UIApplication *app = [UIApplication sharedApplication];
counterTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:counterTask];
//counterTask = UIBackgroundTaskInvalid;
// If you're worried about exceeding 10 minutes, handle it here
theTimer=[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
}];
count=0;
theTimer=[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
[super viewDidLoad];
}
(void)countUp {
count++; NSString *currentCount; currentCount=[[NSString alloc] initWithFormat:@"%d",count]; NSLog(@"timer running in background :%@",currentCount); thecount.text=currentCount; [currentCount release];
}
The above code just sample to count number foreground and background. but after 10 min it is not working.
So please help me and provide me some help for it.