Reputation: 119
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?
Upvotes: 4
Views: 2717
Reputation: 2024
i also got the same issue in "iPhone4s" . it was feeling like none of beacon services is working despite of being bluetooth service on and location service on.
i just rebooted it, and it began to work. for a moment i was happy as it's working now but what is this issue i still could not figure it out . if this happens with end user how he will get to know that he needs to reboot his device?
Upvotes: 2
Reputation: 195
I had a similar problem as mentioned in this question: IBeacon region monitoring not work consistently across devices
I found at that the difference was if the device had Background Refresh enabled or not. To check for this I use the following snippet:
if ([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusAvailable) {
NSLog(@"Background updates are available for the app.");
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied)
{
NSLog(@"The user explicitly disabled background behavior for this app or for the whole system.");
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusRestricted)
{
NSLog(@"Background updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user.");
}
Found in this answer: Detecting user settings for Background App Refresh in iOS 7
Upvotes: 1
Reputation: 496
I don't think you have a defective unit, because I had the exact same problem! Same code worked great on 5S, but did not find beacons using 4S. Turns out (it appears) that the 4S BLE stack works a little differently than the 5S.
The way I wrote my code, I did not start ranging for the beacon until "locationManager didDetermineState forRegion" was called and I determined that I was actually inside the beacon region. This works great on iPhone 5S and you aren't ranging for no good reason. But on a 4S you never get the callback!
But, if you start ranging earlier by putting:
[locationManager startRangingBeaconsInRegion:beaconRegion];
inside the "locationManager didStartMonitoringForRegion" callback, it works like a champ!
Upvotes: 4
Reputation: 131398
It sounds like you might have a defective 4s. To be sure, I would suggest downloading Apple's AirLocate demo (from the 2013 WWDC) and running that on all your devices. It will serve as both a beacon and a "central" (to use BLE terms), aka a beacon receiver.
I have 2 iPhone 4s' and they very definitely both work as both beacon transmitters and receivers, as does our 5th gen iPod touch (the 4 inch model). Sadly, my iPad 2 does not. The mini and iPad 3 are the first iPads to support BLE.
Upvotes: 0