1. The Inquiry
Hello,
I have been implementing a background geofencing feature and, during testing, I found a significant numerical difference in event callback frequency between the older CLCircularRegion API and the newer CLMonitor API (CLMonitor.CircularGeographicCondition), introduced in iOS 17.
My testing was strictly conducted using the "Always Allow" location permission (requestAlwaysAuthorization()). I used both APIs in parallel under identical geofencing conditions and within the same implementation environment. Since a clear difference persists in the data, I suspect this may stem from structural differences in the internal mechanisms of the two APIs rather than an implementation error on my part.
2. Environment and Implementation Details (Proof of Integrity)
I have ensured that my implementation adheres to Apple's guidelines and uses modern Swift concurrency features.
A. Development Environment and Permissions
- iOS Version: iOS 18.x and later
- Xcode Version: Version 17A400 (Version 26.0.1)
- Location Authorization:
Alwayspermission obtained. - Background Mode:
Location updatesis configured correctly inInfo.plist.
B. CLMonitor Initialization and Lifecycle
I implemented robust lifecycle management to ensure CLMonitor is stable and persists correctly:
- Initialization: I performed
CLLocationManagerobject allocation and related service setup (e.g.,CLServiceSessionset toalways) within the call stack frame ofdidFinishLaunchingWithOptions. - Monitor Management: I use an Actor-based Singleton pattern to guarantee that only a single
CLMonitorinstance is used application-wide. - Event Monitoring: Following initialization, I allocated a background
Taskcontaining thefor try await event in await monitor.eventsloop. ThisTaskis explicitly managed to persist in the background until the application is terminated, ensuring continuous event listening.
C. Registration Limit Management
I manage both APIs to ensure they never exceed the recommended maximum of 20 simultaneously monitored regions/conditions. My logic removes the oldest item (LRU) when the limit is reached.
The average registration counts during the test period were highly similar:
CLCircularRegion count | 7.02 |
CLMonitor.CircularGeographicCondition count | 7.04 |
- This confirms that registration count is not the cause of the event frequency difference.
3. Data-Based Observation
The test data (bubble_test_data_for_apple_forum.csv) records the event callbacks for both APIs under identical conditions:
| CLCircularRegion Delegate Total Calls | 617 | 83.56% |
| CLMonitor Event Total Fires | 122 | 16.44% |
| Overall Total Count | 739 | 100% |
A. Key Findings
- CLCircularRegion Operability: 617 calls confirm that core implementation factors (permissions, background setup, etc.) are functioning correctly.
- Disparity in Frequency: Despite running in parallel, the
CLMonitorevent count (122) is approximately 1/5th the frequency of theCLCircularRegioncalls (617). - Efficiency per Registration:
CLCircularRegionaveraged ~0.86 calls per registered item, whileCLMonitoraveraged only ~0.17 calls per registered item.
4. Questions for Apple Engineering
Based on the robust implementation and the data presented, I request a review of the following potential differences between the APIs:
- Internal Mechanism Differences: Are there structural differences in how
CLCircularRegionandCLMonitor.CircularGeographicConditionprocess and schedule geofencing event callbacks? For instance, do they differ in terms of battery optimization priority, event batching, or internal throttling mechanisms? - CLMonitor Event Ratio: Is the phenomenon where
CLMonitorrecords a significantly lower ratio of events compared toCLCircularRegionan intended behavior, or could this be indicative of a specific environmental factor that affects the newer API differently?
Thank you for your time and assistance.