Checkout on leaving a geofence

I implemented opt-in automatic checkout for the native luca iOS app. Core Location monitored a region around the checked-in venue and routed an exit event to checkout; an additional location check covered the active app. Eligibility and Always location permission governed whether monitoring ran.

  • iOS
  • Swift
  • RxSwift
  • Core Location

At a glance

Context and goal

During luca’s contact-tracing phase, a guest could remain checked in after leaving a venue. Automatic checkout needed to respond to a physical boundary crossing even when the app was no longer in the foreground, while keeping the behavior conditional on the user’s choice and location permission.

I implemented the native iOS flow for that behavior. It was part of the earlier contact-tracing product; the feature was later removed as luca changed direction.

Two ways to detect an exit

For a venue that supported automatic checkout, the app took its coordinates and configured radius to create a circular Core Location region. The region monitor subscribed to entry and exit callbacks for that specific region. On an exit, the service initiated the existing checkout operation.

A second detector handled the active-app case. It requested a current position, selected a recent location update, and compared its distance from the venue with the configured radius while accounting for reported horizontal accuracy. The service combined the detectors’ outside-region signals into one checkout path. The active-app check complemented region events; it did not require continuous foreground-style location tracking while the app was in the background.

Automatic checkout used a monitored region and an active-app location check.
flowchart LR
  Eligible[Eligible check-in and opt-in] --> Region[Monitor venue region]
  Eligible --> Active[Check location while app is active]
  Region --> Exit[Outside-region signal]
  Active --> Exit
  Exit --> Checkout[Initiate checkout]

Permission and lifecycle

Monitoring ran only when the user had enabled the feature, was checked in at a supported venue, and had granted Always location access. The service observed changes in permission, check-in availability, and app state so it could update the monitoring path. If the required permission was removed, the enabled setting was turned off.

Core Location region monitoring can wake an iOS app for an exit event. That platform mechanism made the background path possible, while event delivery and completion still depended on system conditions, permissions, and the checkout request. The implementation included a limited retry when checkout failed; it did not turn geofencing into an immediate or unconditional guarantee.

What this work shows

The engineering challenge was the boundary between an iOS system event and an application action: set up a venue-specific region, keep the monitoring tied to an eligible check-in and user consent, and route an exit into checkout. Later revisions separated region monitoring from the active-app location check. The resulting design addressed both paths within one feature, and was retired when the contact-tracing part of the product was removed.