startVisitDetection

abstract suspend fun startVisitDetection(): AFGeofencingResult

Starts visit detection: registers a geofence around each of the member's gym favorites and credits automatic visits from them, in the background and across app restarts. Replaces any session already running, including one started with facilities().startMonitoring(). When location sharing is on, each geofence transition also sends the member's location.

Use it when the member turns on automatic gym check-in - it replaces facilities().startMonitoring(). Call it once: the session survives app restarts and reboots.

Only FAVORITE locations are monitored - the successor of a verified facility. An EXCLUDED location (the successor of a blacklisted one) never is, and a MUTED one is paused - no notifications, no visits - until it is unmuted. Today a favorite is monitored when it is backed by a club, because visits are credited to that club; other kinds of locations join as the backend starts crediting them. Adding, removing, muting or unmuting a favorite re-syncs the geofences of a running session.

Requests background ("Always") location permission when it is missing. Check areLocationServicesEnabled first - with the system switch off this fails with LOCATION_SERVICES_DISABLED. Drive the immediate UI from the returned result and observe subscribeToVisitDetectionStatus for the resolved state: on iOS the "Always" grant arrives a moment after the call returns, and the session then starts on its own.

Android (Kotlin)

lifecycleScope.launch {
when (val result = AFCore.locations().startVisitDetection()) {
is AFGeofencingResult.Success -> showMonitoringOn()
is AFGeofencingResult.Failure -> showMonitoringBlocked(result.status, result.message)
else -> Unit
}
}

iOS (Swift)

let result = try await AFCore.shared.locations().startVisitDetection()
if let failure = result as? AFGeofencingResult.Failure {
showMonitoringBlocked(failure.status, failure.message)
}

Return

AFGeofencingResult.Success once the geofences are registered, or AFGeofencingResult.Failure carrying the blocking AFGeofencingStatus (missing permission, location services off, or no favorite with valid coordinates).

Throws

if the favorites cannot be loaded, or on watchOS, which has no visit detection.