【发布时间】:2014-11-24 13:20:54
【问题描述】:
我正在测试 Apple 的 AirLocate 应用程序,对这种方法的行为有点困惑。
我的代码:
-
我创建了一个 CLBeaconRegion 并将其像键一样添加到字典中
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第一行,然后是区域的标识符?正如您在代码中看到的那样,它应该只是控制台中的 region.identifier(即“Group 57”)。
【问题讨论】:
-
我刚刚清理了代码并按照@davidgyoung 所写的重新安装了应用程序,这很有帮助。
标签: ios cllocationmanager ibeacon