Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iBeacon cannot be found by iPhone 4S

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?

like image 992
Reapo Avatar asked Mar 22 '23 11:03

Reapo


2 Answers

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!

like image 117
TNBtech Avatar answered Apr 29 '23 22:04

TNBtech


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?

like image 27
Nitesh Avatar answered Apr 29 '23 21:04

Nitesh