我遇到了一个涉及 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,另外2个可以找到它们。
我在4S上做过[CLLocationManager isMonitoringAvailableForClass:[CLBeacon class]]
和[CLLocationManager isRangingAvailable]
测试,他们没有失败。
如果这只是我们4S的问题,或者是一般的4S问题,谁能告诉我?