我正在开发4-5个月的区域监控,之前工作正常。在一周或之前,当我们在具有IOS 7.1的设备上测试代码时,我们发现了一个问题:
这是我的代码: - 我制作了一个位置管理器的单例,并在位置管理器中初始化它:
if (locationManager == nil)
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
if ([locationManager respondsToSelector:@selector(activityType)])
{
[locationManager setActivityType:CLActivityTypeFitness];
}
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[locationManager requestAlwaysAuthorization];
}
}
然后我获取用户的当前位置并将其发送到服务器,以获取附近的地理围栏区域,并将其注册为受监控,如下所示:
- (void)startRegionMonitoring:(NSArray*)regions
{
[self unregisterRegionMonitoring];
if ([Helper isValidForRegionMonitoring])
{
[locationManager setDelegate:self];
int MAX_REGION = regions.count > 20 ? 20 : regions.count;
for (int index=0; index<MAX_REGION; index++)
{
NSString *identifier = [NSString stringWithFormat:@"Identfier %d", index+1];
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake([[[regions objectAtIndex:index] valueForKey:@"lat"] doubleValue],
[[[regions objectAtIndex:index] valueForKey:@"lon"] doubleValue]);
CLRegion *region = nil;
double radius = 200.0;
if ([Helper isIOS7])
{
region = [[[CLCircularRegion alloc] initWithCenter:centerCoordinate
radius:radius
identifier:identifier] autorelease];
}
else
{
region = [[[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
radius:radius
identifier:identifier] autorelease];
}
[locationManager startMonitoringForRegion:region];
}
}
}
我尝试了不同的&#34; distanceFilter&#34;,&#34; DesiredAccuracy&#34;的值,并且还使用不同的受监视区域半径值来修复错误。但它没有用。