startMonitoring

abstract suspend fun startMonitoring(): AFGeofencingResult

Starts monitoring presence events for the member’s facilities.

Geofences are registered for all verified facilities. The dwell threshold (how long the member must remain inside a facility region for a visit to be recorded) is determined by the application settings, which the SDK syncs automatically during initialization.

Call stopMonitoring when monitoring is no longer required to release resources.

Return

An AFGeofencingResult indicating the outcome:

Drive the immediate UI for a startMonitoring() call off the returned result, but observe subscribeToStatus for the resolved state. The synchronous result is best-effort: on iOS the Always-upgrade grant is asynchronous, so right after the user taps "Always Allow" the in-call re-read still reports While-Using and returns AFGeofencingResult.Failure. The real state — including reduced accuracy ("Always" granted but Precise Location off) — propagates a beat later and is published to subscribeToStatus, which is the source of truth. The status channel is a state holder (Kotlin StateFlow) and conflates duplicate values, so a repeated startMonitoring() that resolves to the same status won't re-emit even though each call still returns its AFGeofencingResult here. Read isMonitoringActive for an on-demand snapshot.

Throws

if monitoring cannot be started.

Android (Kotlin)

lifecycleScope.launch {
when (val result = AFCore.facilities().startMonitoring()) {
is AFGeofencingResult.Success -> log("Monitoring active")
is AFGeofencingResult.Failure -> showError("Failed: ${result.message}")
}
// Observe subscribeToStatus() for the resolved permission/geofencing
// state (e.g. PERMISSIONS_REDUCED_ACCURACY once iOS propagates it).
}

iOS (Swift)

Task {
let result = try await AFCore.shared.facilities().startMonitoring()
switch result {
case is AFGeofencingResultSuccess:
print("Monitoring active")
case let failure as AFGeofencingResultFailure:
print("Failed: \(failure.message ?? "")")
default: break
}
// Observe subscribeToStatus() for the resolved permission/geofencing
// state (e.g. PERMISSIONS_REDUCED_ACCURACY once iOS propagates it).
}