我正在编写安卓和iOS应用程序,需要找到设备周围的BLE信标。
当我从Android运行我的代码时,它发现我所在的房间里有几个信标。
我有8个信标。
当我从iPhone运行信标代码时,它返回一个恰好包含0个信标的列表。
下面是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self initRegion];
[self locationManager:self.locationManager didStartMonitoringForRegion:self.beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
- (void)initRegion {
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:BEACONUUID];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:BEACONIDENTIFIER];
[self.locationManager startMonitoringForRegion:self.beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"Beacon Found");
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSLog(@"Left Region");
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
self.beaconFoundLabel.text = @"No";
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
CLBeacon *beacon = [beacons lastObject];//<== is always 0
self.beaconFoundLabel.text = @"Yes";
self.proximityUUIDLabel.text = beacon.proximityUUID.UUIDString;
self.majorLabel.text = [NSString stringWithFormat:@"%@", beacon.major];
self.minorLabel.text = [NSString stringWithFormat:@"%@", beacon.minor];
self.accuracyLabel.text = [NSString stringWithFormat:@"%f", beacon.accuracy];
if (beacon.proximity == CLProximityUnknown) {
self.distanceLabel.text = @"Unknown Proximity";
} else if (beacon.proximity == CLProximityImmediate) {
self.distanceLabel.text = @"Immediate";
} else if (beacon.proximity == CLProximityNear) {
self.distanceLabel.text = @"Near";
} else if (beacon.proximity == CLProximityFar) {
self.distanceLabel.text = @"Far";
}
self.rssiLabel.text = [NSString stringWithFormat:@"%ld", (long)beacon.rssi];
}在我的didRangeBeaconsInRegion中,信标NSArray总是显示0个对象。虽然我有8个对象。我下载了几个不属于我的应用程序,它们都能看到我的几个信标。
为什么我的代码看不到我的任何信标?
发布于 2015-06-18 13:46:25
首先检查一下其他应用程序,比如.Locate app,添加你的UDID,然后检查这个应用程序是否显示了你的iBeacon。如果不是,那么苹果IOS有时也会出现问题。然后删除该应用程序。重新启动应用程序。它将为您工作。
https://stackoverflow.com/questions/24678379
复制相似问题