我想实现一个功能,其中我使用 GPS 进行位置更新,当用户不移动时,我希望暂停 GPS 更新。根据“与位置服务保持同步”视频,我这样做了:
//Configure Location Manager
self.theLocationManager = [[CLLocationManager alloc]init];
[self.theLocationManager setDelegate:self];
[self.theLocationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.theLocationManager setActivityType:CLActivityTypeFitness];
NSLog(@"Activity Type Set: CLActivityTypeFitness");
[self.theLocationManager setPausesLocationUpdatesAutomatically:YES];
[self.theLocationManager startUpdatingLocation];
代表:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
NSLog(@"Started location Updates");
}
- (void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager
{
NSLog(@"Pausing location Updates");
}
- (void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
{
NSLog(@"Resuming location Updates");
UIAlertView *pop = [[UIAlertView alloc]initWithTitle:@"Info" message:@"Location Updates resumed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[pop show];
[pop release];
}
我没有得到想要的行为,并且当设备空闲时,甚至没有调用代表“didPause..”和“didResume...”。
理想情况下,GPS 更新必须根据设备的状态和 CLActivityType 停止和恢复,但此处并非如此。
谁能帮助我,我做错了什么?
提前致谢。