I started developing a project using ios-5 , i want to find current location in every 15 min.
this is my code
- (void)applicationDidEnterBackground:(UIApplication *)application {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSDate *newLocationTimestamp = newLocation.timestamp;
NSDate *lastLocationUpdateTiemstamp;
int locationUpdateInterval = 60; //1min
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (userDefaults) {
lastLocationUpdateTiemstamp = [userDefaults objectForKey:@"myevent"];
if (!([newLocationTimestamp timeIntervalSinceDate:lastLocationUpdateTiemstamp] < locationUpdateInterval)) {
NSLog(@"New Location: %@", newLocation);
//[self locationManager:locationManager didUpdateToLocation:newLocation fromLocation:oldLocation];
[userDefaults setObject:newLocationTimestamp forKey:@"myevent"];
}
}
}
The problem I am having is that this code is working in background but i got current location(here is newLocation) in every 5min not after 1min, even i set locationUpdateInterval = 60sec
I have tried everything but not getting exact solution. Thanks in advance!