Implemented the timer in the background as follows and using the XCode 4.5.2
UIDevice *device = [UIDevice currentDevice];
BOOL backgroundSupported = NO;
if ([device respondsToSelector:@selector(isMultitaskingSupported)]) {
backgroundSupported = YES;
}
if (backgroundSupported)
{
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
/*timer code goes here*/
}
and my app is running in background and I have the above code in applicationDidEnterBackground
method in AppDelegate and getting the following message in gdb
Can't endBackgroundTask: no background task exists with identifier 4, or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
I know this question is similar to Can't endBackgroundTask but no answer or suggestions there. any ideas ?
Make sure you are declaring bgTask
like so: UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
I think you may have bgTask
declared as an int or NSNumber.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With