Start tracking geofence

Prev Next

This method allows you to start tracking the geofence of your users.

To begin using the Geofence feature, you must install InsiderGeofence via Cocoapods or Carthage.

This method collects region-related events properly in the foreground without any additional setup, other than adding the following entries into Info.plist:

  • Location Usage Description
  • Location When In Use Usage Description
  • Location Always and When In Use Usage Description
<key>NSLocationUsageDescription</key>
	<string>Your 'Location Usage Description' goes here.</string>
	<key>NSLocationWhenInUseUsageDescription</key>
	<string>Your 'Location When In Use Usage Description' goes here.</string>
	<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
	<string>Your 'Location Always and When In Use Usage Description' goes here.</string>

Method Examples

The following code snippets show how to use this method in Objective-C and Swift.

[InsiderGeofence startTracking];
InsiderGeofence.startTracking()

Tracking in the background

However, if your application needs to track region updates while running in the background or even when it is not running, you must take the following additional steps:

1. Add the Location Always Usage Description entry into Info.plist.

<key>NSLocationAlwaysUsageDescription</key>
<string>Your 'Location Always Usage Description' goes here.</string>

2. Go to your app's target's Signing and Capabilities > Background Modes to enable Background processing and Location updates.

3. Call setAllowsBackgroundLocationUpdates to enable in the background tracking programmatically.

Your title goes here
You can obtain users' location information only if they allow the required permissions.

See how to set the location opt-in attribute for the user.