CLBeacon:我怎样才能与IBeacons保持距离?

Sun*_*hah 2 xcode objective-c ios ibeacon

我怎样才能与iBeacons保持距离?我能够得到他们的proximity,但我怎样才能获得CLBeacon的距离?我使用过Estimote SDK,它给出了距离值,但我不知道如何用CLBeacon来获取它.

 - (void)locationManager:(CLLocationManager *)manager
        didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{

    if (self.beaconRegion) {
        if([beacons count] > 0)
        {
            //get closes beacon and find its major
          CLBeacon *beacon = [beacons objectAtIndex:0];
       }
   }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];

    /*
     * Fill the table with beacon data.
     */
    ESTBeacon *beacon = [self.beaconsArray objectAtIndex:indexPath.row];
    beacon.delegate=self;
    cell.textLabel.text = [NSString stringWithFormat:@"Major: %@, Minor: %@", beacon.major, beacon.minor];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"Distance: %.2f", [beacon.distance floatValue]];
    [beacon connectToBeacon];
    return cell;
}
-(void)beaconConnectionDidSucceeded:(ESTBeacon *)beacon{
    [beacon writeBeaconProximityUUID:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D" withCompletion: ^(NSString *value, NSError *error){
        if(error){
            NSLog(@"Got error here: %@",[error description]);
        }else{
            NSLog(@"Congratulation! you've got sucessfully written UUID in beacon");
        }
    }];

}
Run Code Online (Sandbox Code Playgroud)

Gre*_*reg 6

准确性属性应该给你一个距离:

CLBeacon *beacon = [beacons objectAtIndex:0];
beacon.accuracy
Run Code Online (Sandbox Code Playgroud)

如果它不起作用,请确保调用startRangingBeaconsInRegion:

[_locationManager startMonitoringForRegion:region];
[_locationManager startRangingBeaconsInRegion:region];
Run Code Online (Sandbox Code Playgroud)