Ios 获取错误的估计信标的次要值和主要值
我正在制作Estimote信标并制作演示应用程序,以找出最近信标的次要和主要价值。但是当我检查estimote示例应用程序时,我得到了正确的主值和次值,但当我在项目中使用该代码时,它给了我错误的主值和次值 这是我的密码:-Ios 获取错误的估计信标的次要值和主要值,ios,iphone,ibeacon,estimote,Ios,Iphone,Ibeacon,Estimote,我正在制作Estimote信标并制作演示应用程序,以找出最近信标的次要和主要价值。但是当我检查estimote示例应用程序时,我得到了正确的主值和次值,但当我在项目中使用该代码时,它给了我错误的主值和次值 这是我的密码:- typedef enum : int { ESTScanTypeBluetooth, ESTScanTypeBeacon } ESTScanType; - (id)initWithScanType:(ESTScanType)scanType comple
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;
}
提前感谢。如果您参考了的文档,您将看到主要和次要是
NSNumber
s,尽管可以在字符串上下文中计算NSNumber,通过description
方法获得值,但这不是访问数值的正确方法
你应该使用
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=@"";
}
谢谢你们的重播,但问题是我得到的信标主值和次值不正确。你们有多少信标?我注意到,当您发现信标时,只需重新加载阵列即可。阵列可能正在重新排序。你说的错误是什么意思?不同的号码?零?