测试设备:iPhone 5 (iOS 7)
我有一个应用程序,使用了RegionMonitoring
和updateLocation
。如果进入了某个区域,didEnterRegion
会按预期调用。然后我调用startUpdatingLocation
。但是didUpdateToLocation
方法只被调用了10-20次,而它应该会更新位置直到计时器触发。
相关代码:
CLLocationManager *_locationManager;
NSTimer *_timer;
-(void)initLocationManager
{
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
[_locationManager setActivityType:CLActivityTypeOther];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[_locationManager setPausesLocationUpdatesAutomatically:NO];
[_locationManager setDistanceFilter:kCLDistanceFilterNone];
}
//Did Enter Region, called as expected:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
[_locationManager startUpdatingLocation];
_timer = [NSTimer scheduledTimerWithTimeInterval:300.0f target:self selector:@selector(scheduleMethod:) userInfo:nil repeats:NO];
}
//Timer Fire Method:
- (void) scheduleMethod:(NSTimer*)timer
{
[Utils writeToLog:@"Timer-Stop"];
[_locationManager stopUpdatingLocation];
}
//This Method only called 10-20 Times (in the first 10-20 Seconds) and not the complete 5 Minutes:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[Utils writeToLog:@"LocationUpdate!"];
}
到目前为止,我尝试过:
在locationManagerDidPauseLocationUpdates
方法中重新启动更新,但似乎从未被调用:
-(void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager
{
[WRUtils writeToLog:@"LocationUpdate paused, restarted"];
[_locationManager startUpdatingLocation];
}
在didFailWithError
方法中检查错误,但也没有被调用。并且尝试了一些属性的设置:
[_locationManager setActivityType:CLActivityTypeOther];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[_locationManager setPausesLocationUpdatesAutomatically:NO];
我猜 Plist 设置是正确的: 必需的后台模式 YES 必需的后台模式 项目 0 应用程序注册以获取位置更新
我该如何解决这个问题?