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:

Throws

if monitoring cannot be started.

Android (Kotlin)

lifecycleScope.launch {
when (val result = AFCore.facilities().startMonitoring()) {
is AFGeofencingResult.Success -> log("Monitoring active")
is AFGeofencingResult.Pending -> log("Waiting for permissions: ${result.message}")
is AFGeofencingResult.Failure -> showError("Failed: ${result.message}")
}
}

iOS (Swift)

Task {
let result = try await AFCore.shared.facilities().startMonitoring()
switch result {
case is AFGeofencingResultSuccess:
print("Monitoring active")
case let pending as AFGeofencingResultPending:
print("Waiting for permissions: \(pending.message ?? "")")
case let failure as AFGeofencingResultFailure:
print("Failed: \(failure.message ?? "")")
}
}