> For the complete documentation index, see [llms.txt](https://dev.pointr.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.pointr.tech/features/geofencing/geofence-app-configuration.md).

# Geofence App Configuration

Follow these instructions to enable geofence events in the Mobile SDK for use in your mobile app.

## Position Manager Set Up

In order to trigger geofence events, the SDK must have access to the user's position, so the Position Manager Configuration should be configured accordingly.

{% tabs %}
{% tab title="iOS" %}

```swift
let positionManagerConfiguration = Pointr.shared.configurationManager?.globalConfiguration().positionManagerConfiguration

if positionManagerConfiguration.isCoreLocationEnabled && positionManagerConfiguration.isGpsTrackingEnabledInForeground {
	// Indoor and Outdoor positioning enabled on the foreground
	
}
```

{% endtab %}

{% tab title="Android" %}

```kotlin
val positionManagerConfiguration = Pointr.getPointr()?.configurationManager?.globalConfiguration?.positionManagerConfiguration
if (positionManagerConfiguration?.isBeaconTrackingEnabledInForeground == true && positionManagerConfiguration.isGpsTrackingEnabledInForeground) {
	// Indoor and Outdoor positioning enabled on the foreground
}
```

{% endtab %}
{% endtabs %}

## Geofence Manager Set Up

In order to be notified of geofence events, you need to register as a listener for the Geofence Manager and implement the method defined on `PTRGeofenceManagerDelegate` and `GeofenceManager.Listener` for iOS and Android, respectively.

**Note:** The SDK does not display local notifications. The Geofence Manager only notifies the listeners about the events as they are received; you need to define what UI to display.

{% hint style="info" %}
The SDK provides both 'Enter' and 'Exit' events, which allows you to define what to show the user in each scenario. For more information on how to tune these events, please see[ Tolerance for Enter & Exit events](https://dev.pointr.tech/features/geofencing/fine-tuning-geofence-sensitivity.md).
{% endhint %}

{% tabs %}
{% tab title="iOS" %}

```swift
extension MyClass: PTRGeofenceManagerDelegate {

	func listenToGeofenceEvents() {
		Pointr.shared.geofenceManager?.addListener(self)
	}

	func onGeofenceManagerGeofenceEvent(_ event: PTRGeofenceEvent) {

		let title = event.geofence.title

		// You can add custom values to a geofence on Pointr Cloud Dashboard
		let customValue = event.geofence.extraData["customField"]
    	
		// Check event type
		switch event.type {
    	case .enter:
        	// Handle enter event
			displayEnterNotification(title: title, message: customValue)
    	case .exit:
        	// Handle exit event
			displayExitNotification(title: title, message: customValue)
    	}
		
		// Or check geofence type
		switch event.geofence.type {
    	case .level:
        	// Handle Level Geofence
    	case .global:
        	// Handle Global Geofence
    	}
	}
}
```

{% endtab %}

{% tab title="Android" %}

```kotlin
Pointr.getPointr()!!.geofenceManager!!.addListener(object : GeofenceManager.Listener {
	override fun onGeofenceManagerGeofenceEvent(event: GeofenceEvent) {
		
		val title = event.geofence.name

		// You can add custom values to a geofence on Pointr Cloud Dashboard
		val customValue = event.geofence.extraData["customField"]

		// Check event type
		when(event.type){
			GeofenceEventType.Enter -> {
				// Handle enter event
				displayEnterNotification(title = title, message = customValue)
			}
			GeofenceEventType.Exit -> {
				// Handle exit event
				displayExitNotification(title = title, message = customValue)
			}
		}

		// Or check geofence type
		when (event.geofence.type) {
			GeofenceType.LEVEL -> {
				// Handle Level Geofence
			}
			GeofenceType.GLOBAL -> {
				// Handle Global Geofence
			}
		}
	}
})
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
Geofencing can work when the app is in foreground or background. To receive geofence trigger events when the app is in the background, [set up background positioning](https://dev.pointr.tech/features/indoor-location-blue-dot/background-positioning.md).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://dev.pointr.tech/features/geofencing/geofence-app-configuration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
