2
我開始使用ios-5開發項目, 我想每15分鐘查找當前位置。如何在每15分鐘查找當前位置
這是我的代碼
- (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"];
}
}
}
我遇到的問題是,這個代碼工作的背景,但我得到的當前位置(這裏是newLocation)每5分鐘沒有1分鐘後,即使我設置locationUpdateInterval = 60秒
我已經嘗試了一切,但沒有得到確切的解決方案。 在此先感謝!