我在iOS 7.x上使用Beacons,通常工作正常,但有时当我拨打startRanging...
时,设备启动我错误kCLRangingUnavailable,在检查禁用wifi后,重启蓝牙,然后启动停止airplain模式,这个问题的唯一解决方案是重启手机。
这是我的源代码: @interface RBTMainViewController() @property(nonatomic,retain)CLLocationManager * locationManager; @end
@implementation RBTMainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_locationManager=[[CLLocationManager alloc] init];
_locationManager.delegate=self;
NSUUID *estimoteUUID = [[NSUUID alloc] initWithUUIDString:@"00001111-2222-3333-4444-555566667777"];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:estimoteUUID
identifier:@"Proves Range"];
if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]])
{
[_locationManager startMonitoringForRegion:region];
[_locationManager startRangingBeaconsInRegion:region];
}
else
{
NSLog(@"This device does not support monitoring beacon regions");
}
}
return self;
}
...
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error{
NSLog(@"monitoringDidFailForRange: %@ withError: %@", region, error);
}
- (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region withError:(NSError *)error{
NSLog(@"rangingBeaconsDidFailForRange: %@ withError: %@", region, error);
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{
NSLog(@"monitoringStart: %@", region);
}
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{
NSLog(@"RangingBeacons: %@ in (%@)", beacons, region);
}
@end
这是错误发生时iPhone中的输出:
2014-04-14 13:20:18.628 RangingBeaconsTest[9042:60b] monitoringStart: CLBeaconRegion (identifier:'Proves Range', uuid:<__NSConcreteUUID 0x15554170> 00001111-2222-3333-4444-555566667777, major:(null), minor:(null))
2014-04-14 13:20:23.752 RangingBeaconsTest[9042:60b] rangingBeaconsDidFailForRange: CLBeaconRegion (identifier:'Proves Range', uuid:<__NSConcreteUUID 0x15565390> 00001111-2222-3333-4444-555566667777, major:(null), minor:(null)) withError: Error Domain=kCLErrorDomain Code=16 "The operation couldn’t be completed. (kCLErrorDomain error 16.)"
此代码错误,是不可用的范围。有人可以帮我解决这个问题吗?
感谢。