Geo Tracking - Specs

iOS tracking

Core Location collection, SQLite and Keychain storage, and iOS execution and resumption limits.

Tracking service

GeoTrackingService is a native singleton that implements CLLocationManagerDelegate. The Expo module calls its operations on the main queue and forwards state changes to the React Native interface.

Collection uses Core Location. Transport uses URLSession; connectivity is monitored by NWPathMonitor; positions and state are stored in SQLite; the credential is stored in Keychain.

The service is independent of JavaScript timers. This allows it to persist and send location callbacks without an active React screen, within the execution opportunities that iOS grants the application.

Permissions and application capabilities

Native startup requires a configured identity, an available credential, .authorizedAlways authorization, and location in UIBackgroundModes.

SettingRole
NSLocationWhenInUseUsageDescriptionExplains access while using the app
NSLocationAlwaysAndWhenInUseUsageDescriptionExplains collection and delivery during a background session
UIBackgroundModes: locationEnables the background location capability
Always authorizationRequired by start()

The interface first requests access while using the app, then background access. The iOS request APIs initiate the dialog and the status changes through a callback; if the status is not yet background, the interface instructs the user to review Settings and tap Start again.

Granting system permission does not start the session on its own. start() persists localEnabled=true, records the session start, and clears the timestamp marker for the last native capture.

When Always authorization is removed, the service stops collection and publishes a message. Pending records remain preserved.

How positions are selected

PropertyCurrent setting
desiredAccuracykCLLocationAccuracyBest
activityType.otherNavigation
pausesLocationUpdatesAutomaticallyfalse
showsBackgroundLocationIndicatortrue
distanceFilterDistance from the remote configuration
allowsBackgroundLocationUpdatesEnabled only during collection

Callbacks are sorted by timestamp before processing. The service ignores negative horizontal accuracy, accuracy greater than 10,000 meters, and positions from before the current session started.

The iOS API does not receive an interval parameter identical to the Fused Location Provider's. The service applies intervalSeconds as a filter: a native position is only persisted if enough time has passed since the last accepted native position.

This filter can reduce the number of persisted records, but it does not mean the GPS is activated exactly once per interval. The provider remains responsible for callback frequency.

Synthetic injection receives provider:test, uses the same persistence, and does not change the marker for the last native capture. Test and real positions do not compete for the same time filter.

Local session and remote configuration

Collection depends on all of these conditions: an active local session, enabled remote configuration, Always authorization, background capability, an available credential, and no storage error.

A remote pause calls stopUpdatingLocation() and disables allowsBackgroundLocationUpdates, preserving local authorization. The local stop button remains relevant during this pause.

A local stop shuts down the provider before saving the new state. It then persists localEnabled=false and removes the session start. If the write fails, the current process remains stopped and publishes the error; successful persistence of the stop must not be assumed in that case.

When creating the service, the code restores the state, queue, and credential and reevaluates collection. This restoration occurs when the service is instantiated; it does not promise that the system will launch the application under every circumstance.

SQLite and credential protection

The outbox.sqlite database is stored in Application Support/GeoTracking. The directory is excluded from backup and receives completeUntilFirstUserAuthentication protection.

SQLite is opened with FULLMUTEX, a 5-second lock timeout, WAL, and synchronous=FULL. Inserting the position and state is transactional; acknowledging a batch also changes the queue and counts in the same transaction.

The service does not silently recreate a failed database or empty the queue to continue. Failures to persist state or insert a capture stop collection and are exposed in lastError. Database failures during synchronization, such as reading a batch or acknowledging IDs, follow the synchronization error and retry path; that path does not automatically stop collection.

The token is a generic password item in Keychain, identified by endpoint and device. Its accessibility is AfterFirstUnlockThisDeviceOnly; the token is not part of the state JSON persisted in SQLite or the state sent to the interface.

Changing identity requires an empty queue. The new identity receives an initial state without inheriting the previous active session; changing only the credential for the same identity preserves state. Reconfiguration cancels the current request and increments the generation to ignore old responses.

HTTP transport

The transport uses an ephemeral session with no response cache, a 20-second request timeout, and a 30-second total resource timeout. It does not wait indefinitely for connectivity.

Each synchronization chooses between fetching configuration and sending up to 100 positions. The Authorization header carries the token; redirects are refused to avoid forwarding it to another address.

Only the intersection of sent IDs and acknowledged IDs can be removed. A response that acknowledges none of the batch IDs is a failure, even with HTTP 2xx. After acknowledging a batch, the service continues draining the queue.

See Queue and synchronization for deduplication, lost ACKs, and server capacity.

Synchronization opportunities

The service attempts synchronization after captures, injections, and manual commands, when connectivity returns, and when the application becomes active again.

There is a native 2-second timer. It checks whether there is work and whether the retry wait has ended; it does not mean there is a request every 2 seconds. After success, the next fetch with an empty queue is scheduled for at least 10 seconds later.

Failures produce an exponential wait from 2 to 256 seconds, plus a random value between 0 and 1 second. The timer and new callbacks only trigger an attempt when the process is able to execute.

Each request asks for a limited execution period with beginBackgroundTask. If that period expires, the request is canceled and the period is ended. This protects the queue, but it does not turn the operation into a transfer guaranteed by a system background session.

Important limitation of remote pausing

After location updates are stopped completely, iOS may suspend the process. A timer, a network observer, or a server configuration change does not guarantee that it will resume execution immediately.

Remotely enabling collection for a paused session may therefore only take effect when a new execution opportunity arises, such as reopening the application. The pause and resume trial recorded in the repository was performed with the app in the foreground at that stage.

The code does not implement push to wake the app and start location collection, nor does it promise resumption after force-quitting. Simulator results and field limitations are covered in Tests.

Building and validation

The module declares iOS 16.4 as its minimum and links sqlite3. The project keeps native integration in the repository, including Info.plist and Podfile.

The toolchain guide records the adjustment of expo-modules-jsi to 56.0.13 and pod targets to build the project with Xcode 27. It also records that an unsigned simulator build produced Keychain error -34018; normal signed execution resolved credential storage.

There is an isolated SQLite test in Swift and evidence of collection through iOS simulator callbacks. This storage test is not a full application run and does not replace battery measurements or extended testing on physical devices.

Repository sources

  • geo-demo/modules/geo-monitoring/ios/GeoTrackingService.swift
  • geo-demo/modules/geo-monitoring/ios/GeoTrackingStore.swift
  • geo-demo/modules/geo-monitoring/ios/GeoTrackingTokenVault.swift
  • geo-demo/modules/geo-monitoring/ios/GeoTrackingModels.swift
  • geo-demo/modules/geo-monitoring/ios/GeoMonitoringModule.swift
  • geo-demo/modules/geo-monitoring/ios/GeoMonitoring.podspec
  • geo-demo/ios/geodemo/Info.plist
  • docs/ios-toolchain.md
  • docs/validation-2026-10-15.md

On this page