Reputation: 33
The AppDelegate.m file contains
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIBackgroundTaskIdentifier taskID = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask:taskID];
}];
}
I don't know why I have got this message in the gdb
Can't endBackgroundTask: no background task exists with identifier 1fd57580, or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
Upvotes: 2
Views: 6275
Reputation: 458
If you are using location updates in the background, add the code below at the time of getting location authorization from the user. That's because Apple changed the default value of allowsBackgroundLocationUpdates
to NO
from iOS 9 onwards.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
locationManager.allowsBackgroundLocationUpdates = YES;
}
Upvotes: 1
Reputation: 318804
Your code is all wrong. It should be something like this:
UIBackgroundTaskIdentifier taskID = [application beginBackgroundTaskWithExpirationHandler:^{
// Code to ensure your background processing stops executing
// so it reaches the call to endBackgroundTask:
}];
// Put the code you want executed in the background here
if (taskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:taskID];
}
Upvotes: 5