【问题标题】:Why didDetermineState: forRegion: method called twice为什么 didDetermineState: forRegion: 方法被调用了两次
【发布时间】:2014-11-24 13:20:54
【问题描述】:

我正在测试 Apple 的 AirLocate 应用程序,对这种方法的行为有点困惑。

我的代码:

  1. 我创建了一个 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];
    
  2. 然后我开始监控和测距

    for (CLBeaconRegion *region in self.rangedRegions)
        {
            [self.locationManager startMonitoringForRegion:region];
            [self.locationManager startRangingBeaconsInRegion:region];
        }
    
  3. 委托方法

    - (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”)。

【问题讨论】:

标签: ios cllocationmanager ibeacon


【解决方案1】:

您的应用程序之前运行的范围似乎是两个不同的区域。尝试卸载并重新安装。

【讨论】:

  • 感谢您的回复。我刚刚创建了另一个带有监控和测距功能的简单应用程序,一切正常。我还清理了 AirLocate App 中的代码,它也按预期工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-20
  • 1970-01-01
  • 2013-11-20
  • 2019-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多