I am encountering a weird problem involving an iPhone 4S. I am developing an application that uses iBeacons. The following code is what is running on an iPad mini, iPhone 5s and iPhone 4s, but only the iPad and the 5S are able to respond when they encounter the iBeacon, and the 4S doesn't do anything.
- (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
}
The 4S can broadcast iBeacons without a problem, and the other 2 can find them.
I have done the [CLLocationManager isMonitoringAvailableForClass:[CLBeacon class]]
and [CLLocationManager isRangingAvailable]
tests on the 4S, and they don't fail.
Can anyone enlighten me if this is only a problem with our 4S, or it's a 4S problem in general?