0

I've set up Google Nearby API for my objective-c project to scan for beacons.

The app detects the beacons fine when moving into the range of a beacon but it does't work if I start the app when I'm already in range. I have to walk away from the beacon and return.

I am not using background scanning. The lib version I use is: 0.10.0

My code is:

[GNSMessageManager setDebugLoggingEnabled:YES];

_messageManager = [[GNSMessageManager alloc] initWithAPIKey:@"..."];

_beaconSubscription = [_messageManager subscriptionWithMessageFoundHandler:^(GNSMessage *message) {
    NSLog(@"beacon found: %@",message);
    ...
} messageLostHandler:^(GNSMessage *message) {
    NSLog(@"beacon lost: %@",message);
    ...
} paramsBlock:^(GNSSubscriptionParams *params) {
    params.deviceTypesToDiscover = kGNSDeviceBLEBeacon;
    params.beaconStrategy = [GNSBeaconStrategy strategyWithParamsBlock:^(GNSBeaconStrategyParams *params) {
        params.includeIBeacons = YES;
    }];
}];

I know about the Core Location Framework didEnterRegion / didExitRegion methods that are called only when crossing the boundaries of a beacon region and that I can use didDetermineState method but how does the NearbyAPI work on the inside with these and how can I make the app detect the beacons already in range at startup using it?

1 Answers1

0

This is indeed a bug in the way Nearby Messages monitors iBeacon regions. It uses didEnterRegion/didExitRegion, and as you stated, if you're already in a region when scanning starts, didEnterRegion isn't called.

I've experimented with using didDetermineState, and with a bit of work I'm now able to handle this case. We will include this in the next bug fix release.

In the meantime, here's a trick you can use to avoid the problem while testing your app: Put your beacon into a metal enclosure (a faraday cage), and remove it from the enclosure after your app starts scanning for beacons. This simulates movement into the beacon region. I use a small cocktail shaker for my faraday cage, but a small amount of aluminum foil also works.

Dan Webb
  • 348
  • 1
  • 7
  • We just released version 1.1.0 of [Nearby Messages](https://cocoapods.org/pods/NearbyMessages) with the iBeacon scanning fix. Let me know if you have any problems. – Dan Webb Oct 27 '16 at 22:40