Gym Visits (Geofencing)
Gym Visits credits a visit automatically when the member spends time at one of their favorite gyms, with no check-in needed. Once the app starts visit detection, the SDK watches the member's favorite gyms in the background, keeps doing so across app restarts and device reboots, and records each qualifying visit in the member's activity history.
What you can do
- Start and stop automatic visits with one call each.
- Rely on the member's favorites: adding, removing or muting a favorite gym updates what is watched, with no restart.
- Show a live on/off state and guide the member when something blocks it (permission missing, Location Services off).
- React to arrivals and departures, for example to post a local notification.
Permission. Automatic visits need "Always" location access, so the SDK can notice a visit while the app is in the background. Ask for it in context with Runtime Permissions and explain why; startVisitDetection() also asks for it when it is missing.
Key APIs
| Call | What it is for |
|---|---|
locations().startVisitDetection() | Start automatic visits for the member's favorite gyms |
locations().stopVisitDetection() | Stop them |
locations().subscribeToVisitDetectionStatus() | Drive an on/off toggle and show what is blocking it |
locations().subscribeToVisitEvents() | Arrivals, departures and confirmed visits |
locations().openAppSettings(), openLocationSettings() | Send the member to the right Settings page |
Example
- Android (Kotlin)
- iOS (Swift)
lifecycleScope.launch {
when (val result = AFCore.locations().startVisitDetection()) {
is AFGeofencingResult.Success -> showAutomaticVisitsOn()
is AFGeofencingResult.Failure -> showWhyVisitsAreOff(result.status) // e.g. no "Always" location
else -> Unit
}
}
// The member turns automatic visits off
lifecycleScope.launch {
AFCore.locations().stopVisitDetection()
}
Task {
let result = try await AFCore.shared.locations().startVisitDetection()
if let failure = result as? AFGeofencingResult.Failure {
showWhyVisitsAreOff(failure.status) // e.g. no "Always" location
} else {
showAutomaticVisitsOn()
}
}
// The member turns automatic visits off
Task {
_ = try await AFCore.shared.locations().stopVisitDetection()
}
Visit detection belongs to the member's session: logout() stops it, so start it again after the next sign-in.
UI Reference
Display each favorite gym as a card with its name, address, visit count, distance and monitoring status.
Learn more
- Locations for favorites and the rest of
locations(). - API Reference for visit detection, its status values and events.
- Complete integration guides, including platform setup, are in AIDE Docs.