0
votes

I'm trying to grab the iBeacon advertising code from AirLocate sample code into an empty app. It looks like:

    NSDictionary *peripheralData = nil;

    region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:beaconUuid] major:beaconMajor minor:beaconMinor identifier:beaconIdentifier];
    peripheralData = [region peripheralDataWithMeasuredPower:nil];//[NSNumber numberWithInt:power]

    // The region's peripheral data contains the CoreBluetooth-specific data we need to advertise.
    if(peripheralData)
    {
        [peripheralManager startAdvertising:peripheralData];

        return YES;
    }

The empty app is able to emit iBeacon signal which can be successfully be monitored by another app on another device. But the problem is on another app, locationManager:didEnterRegion: delegate method is followed by locationManager:didExitRegion: very quickly.

Peripheral device: iPad mini 2 retina Central device: iPhone 5S

Running the AirLocate app to separately configure one device as iBeacon emitter and another device as monitor can also reproduce the issue mentioned above.

Some other findings:

  1. If you just leave the receiver app as is, it will report didEnterRegion automatically in a few minutes, followed by didExitRegion quickly, still the same problem.
  2. If you move the emitter app to background mode by pressing home button and enter the same app again, the receiver will trigger another round of those two monitoring methods, still the same problem.

My guess is the frequency of iBeacon advertising is so small (say, once a few seconds) that the receiver may think the region is exited before receiving the package again. It may also be a bug in iOS.

Does anyone know about it?

2

2 Answers

0
votes

Note that you cannot make iOS transmit as an iBeacon in the background. If the lock screen comes up, you will soon get an exit notification on the other device.

By default, an iOS device transmits advertisements at a rate of 30 Hz, but again, the app must be in the foreground. I have measured this with a hardware BLE sniffer. So I doubt transmit frequency is an issue.

0
votes

I want to update my own question with something interesting.

After I upgraded both ends to iOS 7.1.2 released this week which addresses iBeacon stability fix, the situation got a little bit improved: the receiving end will report exit event one minute after enter event during my own app test (previously it happens soon after enter event). If I use Locate Beacon at both ends, I observed the same instability.

Another test I made is to use a third iOS 7.1 (not upgraded to 7.1.2) Phone as the receiver, it doesn't drop from the peripheral at all. Stable as it is expected. So the problem is probably related with receiver device (aka. central).

So it seems a problem with Bluetooth module on my first iPhone receiver. I hope it's not caused by so many Bluetooth debugging on it :)

The problem can always be observed if I use the original iPad mini 2 as peripheral and this iPhone 5s as the central. However, if I use the third iPhone (iPhone 5 if the type matters) as peripheral and still this suspicious iPhone 5s as the central, it's quite stable.

Therefore, if you meet the same strange issue, here are the suggestions:

  1. Upgrade your iOS on both sides
  2. Restart Bluetooth on receiver device (aka. central) sometimes will fix the problem, if not always in your situation.