Use this code to run in background in app delegate class
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask = 0;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
To get gps data call gps location manager inside the above method
eg:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
locationmanager = [[CLLocationManager alloc]init];
[locationmanager setDelegate:self];
locationmanager.distanceFilter = kCLDistanceFilterNone;
[locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[locationmanager startUpdatingLocation];
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask = 0;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
latitude = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.latitude];
longitude = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.longitude];
}