Ad

Our DNA is written in Swift
Jump

Radar: Monitoring CLRegion immediately after removing one fails

This gotcha became apparent to me while putting together the sample app for the seventh and last chapter of my book. There I am monitoring for the 10 regions from a plist which are closest to the user. I was removing all monitored regions and re-added the 10 I am interested in. To update the state I called the requestStateForRegion: but didn’t get a state update. Instead the monitoring failed with error code 5. Fortunately a workaround is possible.

Submitted as rdar://16986842 and to OpenRadar.

Summary

If you remove a region from being monitored by CLLocationManager and immediately try to re-add a new one to monitoring it will fail with error code 5.

Steps to Reproduce

  • Launch an app that is already monitoring for a CLCircularRegion
  • Remove this region from monitoring with stopMonitoringForRegion:
  • Add a new region to be monitored immediately followed by a requestStateForRegion:

Expected Results

  • The new region should be added to the monitored regions
  • requesting a state update right after adding it should just work
  • the state update should return with state inside or outside once that has been determined by CoreLocation.

Actual Results

  • The monitoring fails calling the monitoringDidFailForRegion:withError: passing error code 5
  • didDetermineState:forRegion: is never called

Notes

As a workaround you can execute the state update request at least 1/10th sec later. Then the expected results occur.


Categories: Bug Reports

1 Comment »

  1. The same situation as mine. You save my day dude