Ranging in background errors

I have a problem. My task: run ranging every time when app call didEnterRegion. So I doing this:

func beaconManager(manager: AnyObject, didEnterRegion region: CLBeaconRegion) {
        beaconManager.startRangingBeaconsInRegion(region)
  }

ok, it is fine (I hope) and now I call this method:

func beaconManager(manager: AnyObject, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
        nearBeacon(availableBeacons: beacons, beaconRegion: region)
   }

i the “nearBeacon” method I call stopRangingBeaconsInRegion(region) and then, the didRangeBeacons is called again and again… my question is: why? How can I run didRange when didEnter region was triggered?
I used the Possible to get detected beacon info in didEnterRegion?

Can you double check (e.g., by logging the UUID+major+minor+identifier to the console) if the region object you start ranging with, and then stop ranging with, is the same?

Is the same.

Range: Optional(10517)
Stop: Optional(10517)
Range: Optional(10517)
Stop: Optional(10517)

It’s look like some loop :confused: