我已经通过调用startMonitoringForRegion开始了区域监视.但是我发现didStartMonitoringForRegion被调用了两次,而且didEnterRegion被调用了两次.但我只调用一次startMonitoringForRegion.我的代码
- (void) enableRegionMonitoring:(NSMutableDictionary *)locationInfoDic{
NSLog(@"started Loc Mon");
locMgr = [[CLLocationManager alloc] init];
[locMgr setDelegate:self];
NSString *locationId=[[NSString alloc]init];
double latitude=[[locationInfoDic objectForKey:@"lat"] doubleValue];
double longitude=[[locationInfoDic objectForKey:@"lon"] doubleValue];
if([locationInfoDic objectForKey:@"key"]){
locationId=[locationInfoDic objectForKey:@"key"] ;
}else{
locationId=@"NA";
}
CLLocationCoordinate2D myMonLocation = CLLocationCoordinate2DMake(latitude, longitude);
CLRegion *myRegion = [[CLRegion alloc]
initCircularRegionWithCenter:myMonLocation
radius:100
identifier:locationId];
[locMgr startMonitoringForRegion:myRegion
desiredAccuracy:kCLLocationAccuracyBest];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{
NSLog(@"Region monitoring started\n%@",[region description]);
}
最佳答案 尝试调试.如果你没有时间搞清楚,只需忽略第二个didEnterRegion.即如果didEnterRegion连续两次为同一区域调用,则忽略第二个.