我正在编写安卓和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有时也会出现问题。然后删除该应用程序。重新启动应用程序。它将为您工作。
发布于 2014-07-11 22:51:05
我们之前遇到过类似的问题,请确保您的iBeacon设备在响应来自iOS的扫描请求时不包含特定于制造商的字段。
发布于 2015-06-18 13:37:35
请查收苹果的这张纸条
在尝试监控任何地域之前,您的应用程序应检查当前设备是否支持地域监控。以下是区域监控可能不可用的一些原因:
设备没有必要的硬件来支持区域monitoring.
5.设备处于飞行模式,无法打开必要的硬件电源。
在iOS 7.0及更高版本中,始终在尝试监视区域之前调用CLLocationManager的isMonitoringAvailableForClass:和authorizationStatus类方法。(在OS X v10.8和更高版本以及iOS的早期版本中,请改用regionMonitoringAvailable类。)isMonitoringAvailableForClass:方法告诉您底层硬件是否支持指定类的区域监控。如果该方法返回NO,则您的应用程序不能在设备上使用区域监控。如果返回YES,则调用authorizationStatus方法,判断该app当前是否被授权使用定位服务。如果授权状态为kCLAuthorizationStatusAuthorized,则您的应用程序可以接收其注册的任何地域的越界通知。如果授权状态设置为任何其他值,应用程序将不会收到这些通知。Apple link goes here
https://stackoverflow.com/questions/24678379
复制相似问题