CLLocationManager.RegionEntered not firing when beacons in range

Hey everyone,

Currently im experimenting with iBeacons, and for so far its working, but not with the desired effect.

The fictional scenario is as follows: User of the app enters the office (iBeacon region), and when the person has entered that region a button should appear giving the user the possibility to access features that only should be accessible while he is in the office.

For Android it works flawless, but i got some iOs problems.

I looked in to the 'Find the Monkey' sample, and watched this video

The first part of the video works well, when the phone enters the region it gets an message stating it has entered, but when i open the app, RegionEntered won't fire. When i use the Ranging example from that video, it works well. But i don't want to range individual beacons, i just want to know if the phone is in the designated area when the app is open.

Here is part of my code where i implemented the monitoring for regions, but it is (almost) similar to the one in the tutorial, still the _locationManager_RegionEntered is never fired

public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            SetButtons();
            if (NSUserDefaults.StandardUserDefaults.BoolForKey("ingelogd") == true)
            {
                _locationManager = new CLLocationManager();
                _locationManager.AuthorizationChanged += LocationManagerAuthorizationChanged;

                _locationManager.DidRangeBeacons += LocationManagerDidRangeBeacons;
                _locationManager.RegionEntered += _locationManager_RegionEntered;

                _locationManager.RequestWhenInUseAuthorization();
            }
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();


        }

        void _locationManager_RegionEntered(object sender, CLRegionEventArgs e)
        {
            Debug.WriteLine("Entered region!");
        }

        void LocationManagerDidRangeBeacons(object sender, CLRegionBeaconsRangedEventArgs e)
        {
            foreach (var beacon in e.Beacons)
            {
                Debug.WriteLine("{0}, {1}", beacon.Major, beacon.Minor);
            }               
            if (e.Beacons.Any())
            {

            }               
            if (!e.Beacons.Any())
            {

            }
        }

        void LocationManagerAuthorizationChanged(object sender, CLAuthorizationChangedEventArgs e)
        {
            if(e.Status == CLAuthorizationStatus.AuthorizedWhenInUse)
            {
                _beaconRegion = new CLBeaconRegion(new NSUuid("E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"), "MyRegion");
                _beaconRegion.NotifyOnExit = true;
                _beaconRegion.NotifyOnEntry = true;
                _beaconRegion.NotifyEntryStateOnDisplay = true;
                _locationManager.StartMonitoring(_beaconRegion);
                _locationManager.StartRangingBeacons(_beaconRegion);
            }
        }

Answers

  • RossVernalRossVernal USMember

    I know this was a while ago, but did you ever get to the bottom of this?

  • MaartenHeebinkMaartenHeebink NLMember ✭✭

    @RossVernal said:
    I know this was a while ago, but did you ever get to the bottom of this?

    I did, but unfortunately i cannot tell you how. I have switched employers in the meantime and dont have access to the solution anymore

  • RossVernalRossVernal USMember

    No problem - think I've got it going anyway!

Sign In or Register to comment.