0
votes

I've got 3 beacons on my table, all three have the same UUID but different major and minor numbers. I am expecting to see 3 beacons enter and exit event but only one shows.

I have didEnter and didExit region going and so far, I'm consistently only seeing 1 beacon, the same beacon getting notified when I enter and exit the beacon range.

A list of beacon data are downloaded from our Parse account and I am looping through all of them and telling iOS to monitor the beacon:

    func downloadBeacons()
    {
        var query:PFQuery = PFQuery(className: "Beacon");

        query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
            if error == nil {
                NSLog("Beacons = ", objects!);

                if let objects = objects as? [PFObject] {

                    for beacon in objects {
                        NSLog("------------------------");
                        NSLog("Beacon UUID = %@", beacon["UUID"] as! NSString);
                        NSLog("Beacon major number = %@", beacon["major"] as! NSString);
                        NSLog("Beacon minor number = %@", beacon["minor"] as! NSString);
                        NSLog("Beacon manufactureID = %@", beacon["manufacturerId"] as! NSString);
                        NSLog("Beacon manufacture = %@", beacon["manufacturer"] as! NSString);

                        var uuid:NSUUID = NSUUID(UUIDString: beacon["UUID"] as! String)!;

                        var majorValue:UInt16 = self.stringToUnsignedInt16(beacon["major"] as! String);
                        var minorValue:UInt16 = self.stringToUnsignedInt16(beacon["minor"] as! String);

                        // start monitoring each beacon?
                        var beaconObj = BeaconModel(name: beacon["manufacturerId"] as! NSString,
                            uuid: uuid,
                            majorValue: majorValue,
                            minorValue: minorValue,
                            manufacturer: beacon["manufacturer"] as! NSString);

                        self.startMonitoringBeaconObj(beaconObj);
                    }

                }
            }
            else {
                NSLog("Error: \(error!) \(error!.userInfo!)");
            }

        }
    }

My startMonitoringBeacon method is below:

func startMonitoringBeaconObj(beaconObj:BeaconModel) {
    var beaconRegion:CLBeaconRegion = self.beaconRegionWithBeaconObj(beaconObj);

    LocationManager.sharedInstance.manager.startMonitoringForRegion(beaconRegion);
    LocationManager.sharedInstance.manager.startRangingBeaconsInRegion(beaconRegion);
}

This is my helper method:

func beaconRegionWithBeaconObj(beaconObj:BeaconModel) -> CLBeaconRegion {

    var beaconRegion:CLBeaconRegion = CLBeaconRegion(proximityUUID: beaconObj.uuid, major: beaconObj.majorValue, minor: beaconObj.minorValue, identifier: beaconObj.manufacturer as! String);

    beaconRegion.notifyOnEntry = true;
    beaconRegion.notifyOnExit = true;        

    return beaconRegion;
}

Am I missing something ?

1

1 Answers

0
votes

Region monitoring is based on UUID so since your UUID is same both didEnterRegion: and didExitRegion: would be called once. However, beacon ranging would return you all the varieties of beacons with that UUID (different major & minor values).

If you have three beacons in close proximity (as you mentioned all 3 sitting on your table) broadcasting same UUID then the listener would get callback only once in didEnterRegion. You can try by keeping three beacons far away and then move the listener. You should see didEnterRegion getting called 3 times provided didExitRegion: on previous one is called before you enter same region again.