iOS Geofence CLCircularRegion monitoring. locationManager:didExitRegion does not seem to work as expected

前端 未结 9 776
陌清茗
陌清茗 2020-11-28 03:09

I am currently trying to get my app to monitor particular regions using CoreLocation however I am finding that it does not seem to work as expected, it seems to

9条回答
  •  臣服心动
    2020-11-28 03:42

    This seems to be a bug in CLLocationManager. I've done extensive testing using various region radius configurations and locationManager:didExitRegion does not fire in an expected way. This seems to be either a rather nasty bug or region monitoring does not happen at all like the documentation suggests. I have the test harness available to anyone who wants it:

    http://www.mediafire.com/download/x863zkttltyalk6/LocationTest.zip

    Run it in the simulator and start the test by by selecting Debug -> Location -> Freeway Drive in the iOS simulator menu. The number you see is the distance from the center of the monitored region. The background color will be green while the device is within the monitored region and red when outside the region. The text below the distance are event logs.

    enter image description here

    After running the app, you should see locationManager:didExitRegion fire at 5319 meters from the monitored region. The route will loop every 37 minutes and you'll see the device exiting the region always at 5319 meters.

    I've submitted a radar with Apple (17064346). I'll update this answer once I hear back from them. At least then we'll have some input from the canonical source.

    Here's the detailed text sent to Apple:

    Using a test app on the iOS simulator as well as on an iPhone 5S the CLLocationManager doesn't seem to fire didExitRegion callbacks in an expected way. Regardless of the radius of the circular region being monitored, the callback won't happen until a threshold of around 5000 meters is hit.

    Steps to Reproduce:
    1. Run the attached app
    2. Start region tracking by selecting Debug -> Location -> Freeway Drive in the iOS simulator
    3. Monitor the app. The large # indicates the distance from the center of the watched region.
    4. After about 190 seconds and 5300 meters didExitRegion will finally fire.

    Ths issue does not seem to be related at all to the size of the region. According to the Apple docs, even small regions are supported:

    In iOS 6, regions with a radius between 1 and 400 meters work better on iPhone 4S or later devices. (In iOS 5, regions with a radius between 1 and 150 meters work better on iPhone 4S and later devices.) On these devices, an app can expect to receive the appropriate region entered or region exited notification within 3 to 5 minutes on average, if not sooner.

    Although region events don't happen instantaneously, they should happen fairly quickly. From the Apple docs:

    Region events may not happen immediately after a region boundary is crossed. To prevent spurious notifications, iOS doesn’t deliver region notifications until certain threshold conditions are met. Specifically, the user’s location must cross the region boundary, move away from the boundary by a minimum distance, and remain at that minimum distance for at least 20 seconds before the notifications are reported.

    This is not at all what I am seeing in the test harness. On the simulator the device will always be 5000+ meters away from the region before a locationManager:didExitRegion event occurs.

提交回复
热议问题