我遇到了一个关于iPhone 4S的奇怪问题。我正在开发一个使用iBeacons的应用程序。以下是在iPad mini、iPhone 5s和iPhone 4s上运行的代码,但只有iPad和5S能够在遇到iBeacon时做出响应,而4S什么也没做。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//start ibeacon monitoring mode
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
[self enableMonitoring];
}
- (void)enableMonitoring
{
[self initRegion];
[self locationManager:self.locationManager didStartMonitoringForRegion:self.beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
- (void) initRegion
{
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:UUID]
identifier:@"iBeacon"];
[self.locationManager startMonitoringForRegion:self.beaconRegion];
hasAlerted = NO;
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
ST_UNUSED(manager);
ST_UNUSED(region);
NSLog(@"Beacon Found");
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
ST_UNUSED(manager);
ST_UNUSED(region);
NSLog(@"Left Region");
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
ST_UNUSED(manager);
ST_UNUSED(region);
CLBeacon *beacon = [beacons lastObject];
// stuff gets done here
}
4S手机可以轻松广播iBeacons,而其他两种手机可以找到它们。
我在4S手机上进行了[CLLocationManager isMonitoringAvailableForClass:[CLBeacon class]]
和[CLLocationManager isRangingAvailable]
测试,结果都没有失败。
请问这是否只是我们的4S手机存在问题,还是4S手机普遍存在此问题?