0

I am working on Estimote beacons and making the demo app to find out nearest beacons Minor and Major value. but when i check the estimote example app then i am getting proper major and minor value but when i use that code in my project then it given me wrong minor and major value.

Here is my Code :-

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;
}

Thanks in advance.

Rushabh
  • 3,208
  • 5
  • 28
  • 51

1 Answers1

1

If you refer to the documentation for the ESTBeacon class you will see that major and minor are NSNumbers and although an NSNumber can be evaluated in a string context to get a value via the description method, this is not the correct way to access the numerical value.

You should use

if (beacon.major != nil) {
   cell.lblBeaconMajor.text= [NSString stringWithFormat:@"%ld",[beacon.major intValue]];
}
else {
   cell.lblBeaconMajor.text=@"";
}

if (beacon.minor != nil) {
   cell.lblBeaconMinor.text= [NSString stringWithFormat:@"%ld",[beacon.minor intValue]];
}
else {
   cell.lblBeaconMinor.text=@"";
}
Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • thanks for your replay but issue is that i am getting incorrect beacon major and minor value. – Rushabh Jul 25 '14 at 12:28
  • How many beacons do you have? I note that when you discover beacons you simply reload the array. It is possible that the array is being reordered. Also what do you mean by wrong? Different numbers? Zeros? – Paulw11 Jul 25 '14 at 21:13