To use Geofences to launch campaigns, it is a requirement to have access to the Interactions feature.
This article provides developers information for setting up geo location tracking to allow marketers to configure geo fences.
Contents
- Requirements
- Location Permissions
- Enable the geo location feature
- Disable the geo location feature
- Verify/check if the geo location feature is enabled
- Using the setEventHandler
- Alternative to requesting location tracking permissions
Resources
iOS SDK Configuration
It is strongly advised that only the Emarsys SDK should be used for geofence management within the app. Using 2 or more geo fencing services within an app may lead to the operating system conflicting between the different sets of geo fences resulting in inconsistent behaviour.
1. Requirements
The minimum SDK version should be at least 2.5.0 to support Geofencing,
2. Location Permissions
To request the app has access to the location services of the device, the Info.plist must be extended with the following:
...
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>AlwaysUsage is a must have for region monitoring (or some description of your choice)</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>AlwaysUsage is a must have for region monitoring (or some description of your choice)</string>
When testing the app, please ensure that the contact is being asked to allow the app access to the geo location.
3. Enable the geo location feature
To enable the geo location feature, use the enable
method:
Objective-C
[Emarsys.geofence enableWithcompletionBlock:^(NSError *error) {
if (error) {
NSLog(error);
}
}];
Swift
Emarsys.geofence.enable { error in
if let error = error {
print("Error: \(error.localizedDescription)")
}
}
4. Disable the geo location feature
To disable the geo location feature, use the disable
method:
Objective-C
[Emarsys.geofence disable];
Swift
Emarsys.geofence.disable()
5. Verify/check if the geo location feature is enabled
To verify/check if the geo location feature is enabled, use the isEnabled
method:
Objective-C
[Emarsys.geofence isEnabled];
Swift
Emarsys.geofence.isEnabled()
6. Using the setEventHandler
In order to react to an event triggered by a geofence, it is possible to register for it using the setEventHandler
method. The eventHandler is a callback for a Geofence event.
Objective-C
[Emarsys.geofence setEventHandler:<eventHandler: id<EMSEventHandler>>];
Swift
Emarsys.geofence.eventHandler = <eventHandler: EMSEventHandler>
7. Alternative to requesting location tracking permissions
The requestAlwaysAuthorization
method is an alternative method that can be used to request location tracking permissions. If the app has already requested permissions, it is not necessary to be used.
Objective-C
[Emarsys.geofence requestAlwaysAuthorization];
Swift
Emarsys.geofence.requestAlwaysAuthorization()