Overview

Skill Level: Any

Device Location Awareness (DLA) is provided in the IBM Mobile App Messaging SDK for iOS apps developed in Xamarin, by default. If you want to use beacons or geofences, you can modify the default settings in the MCEConfig.json file to meet the specific requirements of your app.

Prerequisites

Before configuring the IBM Mobile App Messaging SDK for Xamarin for geofence and beacon integration, configure locations in the Device Location Awareness (DLA) service. For more information, see Device Location Awareness.

 

About this task

The location section of the MCEConfig.json file enables DLA for beacons and geofences in the IBM Mobile App Messaging SDK for iOS apps developed in Xamarin.

Note: If you do not want to use beacons or geofences, remove the corresponding section from the MCEConfig.json file. For example, to remove beacon support, remove ibeacon, or to remove geofence support, remove geofence. If you do not want DLA, remove the entire location section. 

 "location": {

"The sync key is only used to customize the iBeacon and Geofence syncing service, it is not required for those features":"",
"sync": {
"Location Sync radius is in meters, default 100km":"",
"syncRadius": 100000,

"Specify how long to wait before syncing again on significant location change in seconds, default 5 minutes":"",
"syncInterval": 300
},

"Please note, the existince of the location key will enable geofence location support, if geofence support is not desired, remove the key":"",
"geofence":{
"choose one of the following values for accuracy: ": ["best", "10m", "100m", "1km", "3km"],
"accuracy": "3km"
},

"Please note, the existince of the ibeacon key will enable iBeacon support, if iBeacon support is not desired, remove the key":"",
"ibeacon": {
"UUID": "SET YOUR IBEACON UUID HERE"
},
},

 

 You can modify the following settings:

syncRadius lets you customize sync services for geofences and beacons. This setting specifies the radius from a site or zone at which the SDK syncs location info with the DLA server. When the mobile device crosses the sync radius, the server downloads a list of site and zone locations to the device for monitoring. A low value causes a full sync more frequently. Sync radius is different than the geofence radius that is specified in the DLA UI. The geofence radius specifies the radius at which a location event is triggered. The default value for syncRadius is 100000 meters (100 km).

syncInterval lets you customize sync services for geofences and beacons. syncInterval specifies the number of seconds to wait before syncing after a significant location change. The default value for syncInterval is 300 seconds (5 minutes). The minimum allowed value is 300 seconds. If you try to set the syncInterval to a value that is lower than 300 seconds, the SDK resets the value to 300 seconds.

Accuracy represents the accuracy assigned to the location manager in the SDK. A higher accuracy setting uses more battery but delivers more accurate location information. A lower accuracy setting uses less battery but delivers less accurate location information. Available accuracy levels include best, 10 m, 100 m, 1 km, and the default 3 km.

UUID specifies a UUID for the beacons that you are tracking in locations. In DLA, beacons are identified by a hierarchical combination of a UUID, a major number, and a minor number, where UUID represents a group of associated beacons, such as the beacons associated with an organization.

 

If you are using either geofences or beacons, configure locations by performing these steps:

Step-by-step

  1. In the target app’s Project Settings screen, turn on the Background Modes capability in the Capabilities tab, and then enable Location updates and Background fetch.

  2. To use location services, add the NSLocation key and string to the app project’s Info.plist file.

    NSLocationAlwaysUsageDescription requests permission from the mobile app user to use location services when your app is running in the background. Because Apple recently started prohibiting apps from sharing location data with third parties when explicit user consent is absent, you might want to use NSLocationAlwaysUsageDescription to tell users how the SDK uses location data. The SDK stores location data locally on the device and when a geofence event is triggered, the event is sent to MCE, which a third party. The event does not contain raw location data. To convince users to grant permission, you might also want to let them know that battery usage is minimal when location sharing is enabled.

    <key>NSLocationAlwaysUsageDescription</key>
    <string>The SDK stores location data locally on the device and
    when a geofence event is triggered, the event is sent to MCE,
    which a third party. The event does not contain raw location data.
    Battery usage is minimal when sharing location.</string>

    Note: You might also consider using the NSLocationWhenInUseUsageDescription key to allow location access only when the app is in use.

     

    iOS 11 (and later)

    For iOS 11, you must add both the NSLocationWhenInUseUsageDescription key and the NSLocationAlwaysAndWhenInUseUsageDescription key to the Info.plist file.

    <key>NSLocationAlwaysUsageDescription</key>
    <string>The SDK stores location data locally on the device and
    when a geofence event is triggered, the event is sent to MCE,
    which a third party. The event does not contain raw location data.
    Battery usage is minimal when sharing location.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>The SDK stores location data locally on the device and
    when a geofence event is triggered, the event is sent to MCE,
    which a third party. The event does not contain raw location data.
    Battery usage is minimal when sharing location.</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>The SDK stores location data locally on the device and
    when a geofence event is triggered, the event is sent to MCE,
    which a third party. The event does not contain raw location data.
    Battery usage is minimal when sharing location.</string>

     

  3. (Optional) If you want to be notified when a geofence or beacon event occurs, implement the following delegates.

    Note: If you implemented the delegates when configuring locations for Android, you can skip this step.

    Beacon entry:

    SDK.Instance.BeaconEntered += (beaconRegion) => {
    // use beaconRegion.Minor
    // use beaconRegion.Major
    }

    Beacon exit: 

    SDK.Instance.BeaconExited += (beaconRegion) => {
    // use beaconRegion.Minor
    // use beaconRegion.Major
    }

    Geofence entry:

    SDK.Instance.GeofenceEntry += (geofence) => {
    // use geofence.Latitude
    // use geofence.Longitude
    // use geofence.Radius
    }

    Geofence exit:

    SDK.Instance.GeofenceExited += (geofence) => {
    // use geofence.Latitude
    // use geofence.Longitude
    // use geofence.Radius
    } 

Expected outcome

Location Universal Behavior events are available in Watson Campaign Automation queries and programs for iOS apps that are developed in Xamarin. For information about DLA, see DLA. For information about concepts and advanced features of the IBM Mobile App Messaging SDK for Xamarin, see Documentation.

Go Back to the Mobile App Messaging home page.

Join The Discussion

Your email address will not be published. Required fields are marked *