gpt4 book ai didi

objective-c - didStartMonitoringForRegion 一次调用两次 startMonitoringForRegion

转载 作者:搜寻专家 更新时间:2023-10-30 19:46:15 24 4
gpt4 key购买 nike

我已经通过调用 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 为同一区域连续调用两次,则忽略第二次。

关于objective-c - didStartMonitoringForRegion 一次调用两次 startMonitoringForRegion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15265323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com