Search code examples
iosiphoneobjective-cbluetoothibeacon

Receive iBeacon with Same uuid and different major, minor in background


I want to show LocalNotification when device enter some beacon range in background. When device enter the range of Beacon:A (UUID:xxx major:1 minor:1), LocalNotification shows correctly, but after this, when device enter the range of Beacon:B(UUID:xxx major:2 minor:2), nothing happened. Does didDetermineState not call when device already entered the range of same UUID in background state ? Any help will be appriciated.


Solution

  • My guess is that you are monitoring on a single CLBeaconRegion without specifying all of the identifiers. If you do this:

    CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:major identifier:@"myRegion"]]];

    Or this:

    CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"myRegion"]];

    Then iOS will only notify you once when it sees either of the beacons. By not specifying the minor in your regions, then you are telling iOS to treat all beacons as part of a single region regardless of minor value.

    If you want to get separate state notifications for each beacon, construct two different regions like this:

    CLBeaconRegion *regionForBeaconA = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:major minor:1 identifier:@"myRegionForBeaconA"]];

    CLBeaconRegion *regionForBeaconB = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:major minor:2 identifier:@"myRegionForBeaconB"]];

    And start monitoring on both regions. Then you will get a different callback for both Beacon A and Beacon B.