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

时间:2014-06-04 10:57:34

标签: ios objective-c xcode 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");
        }
    }];

}

2 个答案:

答案 0 :(得分:6)

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

CLBeacon *beacon = [beacons objectAtIndex:0];
beacon.accuracy

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

[_locationManager startMonitoringForRegion:region];
[_locationManager startRangingBeaconsInRegion:region];

答案 1 :(得分:0)

准确性属性是Apple的估计,您自己的计算(基于信标的TX和RSSI)的精确程度。如果它是“0.1”,这意味着,您计算的距离可能不会超过10厘米。但如果准确度为“1.5”且距离计算结果为3米,则表示信标可能在1.5到4.5米的范围内。

我的猜测:精确度属性测量当前RSSI,并通过与先前发现的平均RSSI的差异来计算。

回答你的问题:你能读Java吗?我现在手头没有C代码......

<input type="button" value="Print" onclick="document.getElementById('PDFtoPrint').focus(); document.getElementById('PDFtoPrint').contentWindow.print();">

r是以米为单位的估计距离。 txPower是信标的Tx-Power(使用AltBeacons,这是20字节“Beacon ID”之后的有效载荷的字节)。

相关问题