【问题标题】:iOS ibeacon identifier in initWithProximityUUID:(NSUUID *)proximityUUID identifier:(NSString *)identifier?iOS ibeacon 标识符 initWithProximityUUID:(NSUUID *)proximityUUID identifier:(NSString *)identifier?
【发布时间】:2015-05-12 13:35:56
【问题描述】:

我正在学习以下教程:

http://www.appcoda.com/ios7-programming-ibeacons-tutorial/

但是,我没有使用 iPhone 作为信标,而是使用制造商提供的真实信标(RECO、Estimote)。

我不明白下一行中的标识符字段应该使用什么:

// Setup a new region with that UUID and same identifier as the broadcasting //beacon
self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"what should I use here?"];

我可以修改信标的 UUID、主要和次要值,但没有修改标识符的选项。标识符是什么?

【问题讨论】:

    标签: ios ibeacon identifier


    【解决方案1】:

    该字符串标识符只是一个唯一键,您可以使用它来识别区域。 您可以在字符串中输入您想要的任何值,只要您在要替换正在测距/监控的区域或停止测距/监控时再次使用相同的值来识别区域那个地区。

    以下示例将开始监控两个区域(基于两个不同的 UUID,具有两个不同的标识符“first_region”和“second_region”:

    [_locationManager startMonitoringForRegion: 
        [[CLBeaconRegion alloc] initWithProximityUUID:first_uuid 
                                identifier:@"first_region"]];
    
    [_locationManager startMonitoringForRegion: 
        [[CLBeaconRegion alloc] initWithProximityUUID:second_uuid
                                identifier:@"second_region"]];
    

    然后您可以使用如下代码停止对 second 区域的监控:

    [_locationManager startMonitoringForRegion: 
        [[CLBeaconRegion alloc] initWithProximityUUID:second_uuid
                                identifier:@"second_region"]];
    

    上面代码行中重要的是这个“second_region”标识符字符串。要正确停止监控,它必须与您用于开始监控的字符串匹配地区。

    【讨论】:

      【解决方案2】:

      如果你只使用一个区域,那么你可以给它任何字符串值,如下所示;有关更多信息,请参阅此帖子https://stackoverflow.com/a/20566695/1351327

      static NSString * const kIdentifier = @"SomeIdentifier";
      static NSString * const kUUID = @"124C5678-4444-1111-2222-134556728422";
      
      // Then create the region
      
      NSUUID *proximityUUID = [[NSUUID alloc] initWithUUIDString:kUUID];
      CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:proximityUUID identifier:kIdentifier];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-06
        • 1970-01-01
        • 1970-01-01
        • 2018-01-24
        • 2021-07-31
        • 1970-01-01
        • 2014-02-05
        • 1970-01-01
        相关资源
        最近更新 更多