AFGeofence Location Delegate
Internal class implementing the CLLocationManagerDelegateProtocol to handle geofence events. This class is responsible for receiving notifications when a device enters or exits a monitored region, and also handles dwell time calculations within a region.
Dwell detection uses three layers:
Heartbeat timer — A repeating NSTimer fires every 60 seconds to evaluate dwell thresholds. This is reliable in background because
startUpdatingLocation()(withallowsBackgroundLocationUpdates+pausesLocationUpdatesAutomatically = false) keeps the app alive and prevents iOS from suspending it.Location updates — Each didUpdateLocations callback also checks thresholds, providing an opportunistic dwell evaluation on every location change.
Exit fallback — If the app was killed and relaunched for an exit event, the dwell threshold is checked on region exit using the persisted entry timestamp.
Entry timestamps are persisted to NSUserDefaults via AFGeofenceStore so that dwell duration can be computed even after a process kill. The dwellEmitted set prevents duplicate dwell events when multiple layers trigger.
All geofence transition events (ENTER, EXIT, DWELL) and errors are emitted through AFGeofencingInternal.