Source: https://developers.woosmap.com/products/geofencing-sdk/ios-sdk/guides/monitor-beacons/

> For clean Markdown of any page, append `.md` to the page URL.

> For a complete documentation index, see https://developers.woosmap.com/llms.txt

# Monitor point of interest with beacon fencing



## Monitor beacon proximity thanks to the Indoor Search API

After starting the beaconTracking profile, beacon identifiers will be automatically retrieved from the Woosmap Platform and beacons will be automatically monitored by the SDK.

But first you need to set keys and a delegate to monitor entry/exit events:

```swift
let dataRegion = DataRegion()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // Set Woosmap API Private key
        WoosmapGeofenceManager.shared.setWoosmapAPIKey(key: WoosmapKey)

        // Set delegate of protocol Region 
        WoosmapGeofenceManager.shared.getLocationService().regionDelegate = DataRegion()

        // Start beacon tracking profile
        WoosmapGeofenceManager.shared.startTracking(configurationProfile: ConfigurationProfile.beaconTracking)

        return true
}
```

Region callbacks are triggered each time a user enters or exits a beacon-fence:

```swift
import WoosmapGeofencing

public class DataRegion: RegionsServiceDelegate {

    // the didEnterPOIRegion() is called when a user enters in the geofence 
    public func didEnterPOIRegion(event: Region) {
        
        // check first if the event.type is equal to "beacon" 
        if event.type == "beacon"
        {
            // retrieve POI data from the device database
            if let beacon = IndoorBeacons.getByID(idstore: event.identifier ?? "") as POI? {
                print("Woosmap Geofencing Events: woos_geofence_entered_event - Beacon UUID:" + beacon.BeaconID);
            }
            else {
                // error: Related beacon doesn't exist
            }
        }
    }
```

In the `didExitPOIRegion` method, an additional data is provided by the regionLog object: `spentTime`
It represents the time spent in the geofence between the entry event and the exit event.
