获得错误的小型和主要价值的estimote灯塔

时间:2014-07-25 11:16:33

标签: ios iphone ibeacon estimote

我正在研究Estimote信标并制作演示应用以找出最接近的信标Minor和Major值。但是当我检查estimote示例应用程序时,我得到了正确的主要和次要值但是当我在我的项目中使用该代码时,它给了我错误的次要和主要价值。

这是我的代码: -

typedef enum : int
{
    ESTScanTypeBluetooth,
    ESTScanTypeBeacon

} ESTScanType;


- (id)initWithScanType:(ESTScanType)scanType completion:(void (^)(ESTBeacon *))completion
{
    self = [super init];
    if (self)
    {
        self.scanType = scanType;
        self.completion = [completion copy];
    }
    return self;

}
- (void)viewDidLoad
{
    [super viewDidLoad];

  self.beaconManager = [[ESTBeaconManager alloc] init];
    self.beaconManager.delegate = self;

   self.region = [[ESTBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:BEACONUUID1]
        identifier:@“AllBeacons”];
    if (self.scanType == ESTScanTypeBeacon)
    {
        [self.beaconManager startRangingBeaconsInRegion:self.region];
    }
    else
    {
        [self.beaconManager startEstimoteBeaconsDiscoveryForRegion:self.region];
    }

    // Do any additional setup after loading the view from its nib.
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];

    /*
     *Stops ranging after exiting the view.
     */
    [self.beaconManager stopRangingBeaconsInRegion:self.region];
    [self.beaconManager stopEstimoteBeaconDiscovery];
}

#pragma mark - ESTBeaconManager delegate

- (void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
{
    self.beaconsArray = beacons;

    [tblView reloadData];
}

- (void)beaconManager:(ESTBeaconManager *)manager didDiscoverBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
{
    self.beaconsArray = beacons;

    [tblView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    __weak  BeconsDetailCell *cell=(BeconsDetailCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BeconsDetailCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

     ESTBeacon *beacon = [self.beaconsArray objectAtIndex:indexPath.row];

    //beacon name

    cell.lblBeaconname.text = @"Estimote Beacon";


    //Beacon major

    NSString *strMajor = [NSString stringWithFormat:@"%@",beacon.major];
    strMajor = [strMajor stringByReplacingOccurrencesOfString:@"-" withString:@""];
    cell.lblBeaconMajor.text = strMajor;

    //Beacon minor

    NSString *strMinor = [NSString stringWithFormat:@"%@",beacon.minor];
    strMinor = [strMinor stringByReplacingOccurrencesOfString:@"-" withString:@""];
    cell.lblBeaconMinor.text = strMinor;

    //Beacon distance

    switch (beacon.proximity)
    {
        case CLProximityUnknown:
            cell.lblBeaconDistance.text = @"Unknown";
            break;

        case CLProximityFar:
            cell.lblBeaconDistance.text = @"Far";
            break;

        case CLProximityNear:

            cell.lblBeaconDistance.text = @"Near";
            break;

        case CLProximityImmediate:
            cell.lblBeaconDistance.text = @"Immediate";
            break;

        default:
            break;
    }
    return cell;
}

提前致谢。

1 个答案:

答案 0 :(得分:1)

如果您参考ESTBeacon class的文档,您将看到主要和次要是NSNumber,尽管可以在字符串上下文中评估NSNumber以通过{{1获取值方法,这不是访问数值的正确方法。

你应该使用

description