I have a timer which shows the NSTime of a user's work out. Location manager and that timer stops updating when my app goes to background mode. How can i make them updating when my app is in background mode?
I have a view called RunViewController which has start button. When user clicks that button, timer and location manager starts. Code is:
-(void)startRun{
timeSec = 0;
timeMin = 0;
timeHour = 0;
NSString* timeNow = [NSString stringWithFormat:@"%02d:%02d:%02d",timeHour , timeMin, timeSec];
//Display on your label
lblTime.text = timeNow;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest; //kCLLocationAccuracyBest
[locManager setDistanceFilter:3]; //kCLDistanceFilterNone
[locManager startUpdatingLocation];
locationManagerStartDate = [[NSDate date] retain];
}
In - (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
simply draws a line on map from old location to new location and save that location in an array.
Thanks in advance.