Search code examples
ioscllocationmanagerregionibeacon

Ranging beacons interval


On iOS, in my application delegate I start region monitoring and as soon as I enter in a beacon region I start the ranging logic, using locationManager:didRangeBeacons:inRegion. According to the Apple documentation, this method should be called only when the the region comes within the range or out of the range or when the range changes.

My problem is that I get a call to this method every second as long as I am inside the region. How to decrease the number of calls to this method while still ranging?


Solution

  • According to the Docs:

    "The location manager calls this method whenever a beacon comes within range or goes out of range. The location manager also calls this method when the range of the beacon changes; for example, when the beacon gets closer."

    Whats probably happening is the range is changing slightly which is causing the behaviour you describe.

    Why is this a problem

    EDIT:

    IN the background you will get notified of entering regions via the app delegate method:

    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{}
    

    You can use this to determine the state:

    if(state == CLRegionStateInside)
    {
        //Inside a region:
    }
    else if(state == CLRegionStateOutside)
    {
        //Outside a region
    }
    else {
        //Something else
    }
    

    You can use this to gather a limited amount of information or prompt the user to load the application via a local notification. When your app resumes you can then gather more information via the locationManager.