-(void) applicationDidEnterBackground:(UIApplication *) application
{
// First tracking and check that you are on a device that supports this feature.
// Also you will want to see if location services are enabled at all.
[locationManager startMonitoringSignificantLocationChanges];
}
-(void) sendBackgroundLocationToServer:(CLLocation *)location
{
// REMEMBER. We are running in the background if this is being executed.
// We can't assume normal network access.
// bgTask is defined as an instance variable of type UIBackgroundTaskIdentifier
// Note that the expiration handler block simply ends the task. It is important that we always
// end tasks that we have started.
bgTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:
^{
[[UIApplication sharedApplication} endBackgroundTask:bgTask];
}];
// ANY CODE WE PUT HERE IS OUR BACKGROUND TASK
// For example, I can do a series of SYNCHRONOUS network methods (we're in the background, there is
// no UI to block so synchronous is the correct approach here).
// ...
// AFTER ALL THE UPDATES, close the task
if (bgTask != UIBackgroundTaskInvalid)
{
[[UIApplication sharedApplication} endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
}
0 Comment(s)