Ios 为什么调用了两次Estate:forRegion:方法
我正在测试苹果的AirLocate应用程序,对这种方法的行为有点困惑 我的代码:Ios 为什么调用了两次Estate:forRegion:方法,ios,cllocationmanager,ibeacon,Ios,Cllocationmanager,Ibeacon,我正在测试苹果的AirLocate应用程序,对这种方法的行为有点困惑 我的代码: 我创建了一个CLBeaconRegion,并将其像键一样添加到字典中 self.rangedRegions = [[NSMutableDictionary alloc] init]; CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc]initWithUUIDString:@"E2C56DB5-
self.rangedRegions = [[NSMutableDictionary alloc] init];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc]initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"] identifier:@"Group 57"];
self.rangedRegions[region] = [NSArray array];
for (CLBeaconRegion *region in self.rangedRegions)
{
[self.locationManager startMonitoringForRegion:region];
[self.locationManager startRangingBeaconsInRegion:region];
}
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if(state == CLRegionStateInside)
{
NSLog(@"INSIDE REGION %@",region.identifier);
}
else if(state == CLRegionStateOutside)
{
NSLog(@"OUTSIDE REGION %@",region.identifier);
}
else
{
return;
}
}
2014-11-24 16:10:42.482 AirLocate[741:60b] OUTSIDE REGION E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
2014-11-24 16:10:42.977 AirLocate[741:60b] OUTSIDE REGION Group 57
2014-11-24 16:11:31.061 AirLocate[741:60b] INSIDE REGION E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
2014-11-24 16:11:31.656 AirLocate[741:60b] INSIDE REGION Group 57
为什么此方法对CLRegionStateInside和CLRegionStateOutside调用了两次?
为什么控制台首先输出UUID,然后输出区域标识符?正如您在代码中所看到的,它应该是console中唯一的region.identifier(即“Group 57”)。看起来您的应用程序与以前运行的应用程序有两个不同的区域。尝试卸载并重新安装。我刚刚清理了代码并重新安装了@davidgyoung编写的应用程序,这很有帮助。感谢您的回复。我刚刚创建了另一个简单的应用程序,带有监控和测距功能,一切正常。我还清理了AirLocate应用程序中的代码,它也按预期工作。