我该如何获取iBeacons的距离?我能够获取它们的proximity
,但是如何从CLBeacon获取距离呢?我已经使用Estimote SDK进行了开发,这个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");
}
}];
}