Device location awareness for Cordova apps

To enable device location awareness (DLA) in your Cordova app, do the following:

  1. In the root directory of your project, open the CampaignConfig.json file.
  2. Make sure the location plugin in the plugins section is enabled.
{
  "plugins": {
    "useRelease": false,
    
    "Required Mobile-Push plugins": "<true/false>, enable or disable plugin",
    "cordova-acoustic-mobile-push": true,
    "cordova-acoustic-mobile-push-plugin-ios-notification-service": true,
    "cordova-acoustic-mobile-push-plugin-inapp": true,
    "cordova-acoustic-mobile-push-plugin-inbox": true,
    
    "Optional Mobile-Push plugins": "<true/false>, enable or disable plugin",
    "cordova-acoustic-mobile-push-plugin-action-menu": true,
    "cordova-acoustic-mobile-push-plugin-beacon": true,
    "cordova-acoustic-mobile-push-plugin-calendar": true,
    "cordova-acoustic-mobile-push-plugin-displayweb": true,
    "cordova-acoustic-mobile-push-plugin-geofence": true,
    "cordova-acoustic-mobile-push-plugin-location": true,
    "cordova-acoustic-mobile-push-plugin-passbook": true,
    "cordova-acoustic-mobile-push-plugin-snooze": true
  }
}
  1. Review the settings in the location section of CampaignConfig.json.
  2. If the autoInitialize property in the location section is set to false, start location services and monitoring for locations by calling the manualLocationInitialization method.

Location module

Methods

(static) locationAuthorization()

This method reports if the app has authorization to use location services. It can report the following values:

  • -2 - the app has foreground only access to location services (use the manualLocationInitialization method)
  • -1 - the app is not authorized to use location services
  • 0 - the app has not yet requested to use location services (use the manualLocationInitialization method)
  • 1 - the app has complete access to location services

(static) manualLocationInitialization()

Use this method to manually initialize location services for the Campaign library. This lets you delay location services initialization until desired.

To enable the method, you must set the Auto initialize location feature to false in the CampaignConfig.json file.

(static) setLocationAuthorizationCallback()

This callback is called when access to the location services changes.

(static) setLocationUpdatedCallback(callback)

Set callback for location database updates.

ParameterTypeDefinition
callbacklocationCallbackCallback which will be called when the database is updated.

(static) syncLocations()

Prompts the Campaign library to synchronize the geofences with the server. This can only be called once every 5 minutes.

Type definitions

locationCallback

The location callback includes no data. When it is received you should refresh your inbox database.

Beacon module

Methods

(static) beaconEnabled(callback)

Query if iBeacons are enabled or disabled.

ParameterTypeDefinition
callbackbeaconEnabledCallbackResponse callback

(static) beaconRegions(callback)

Query the current iBeacon regions.

ParameterTypeDefinition
callbackbeaconRegionsCallbackThe callback with the current iBeacon regions.

(static) beaconUUID(callback)

Query if iBeacon global UUID currently setup.

ParameterTypeDefinition
callbackbeaconUUIDCallbackResponse callback.

(static) setBeaconEnterCallback(callback)

Set callback for entering iBeacon regions.

ParameterTypeDefinition
callbackbeaconCallbackCallback function for entering iBeacon regions.

(static) setBeaconExitCallback(callback)

Set callback for exiting iBeacon regions.

ParameterTypeDefinition
callbackbeaconCallbackCallback function for exiting iBeacon regions.

Type definitions

Beacon

PropertyTypeDefinition
majorIntegerMajor of beacon region
minorIntegerMinor of beacon region
locationIdStringIdentifier of beacon region

beaconCallback(beacon)

PropertyTypeDefinition
beaconBeaconBeacon region entered or left.

beaconEnabledCallback(status)

PropertyTypeDefinition
statusBooleantrue if iBeacons are enabled, false otherwise.

BeaconMajor

PropertyTypeDefinition
majorIntegerMajor of beacon region

beaconRegionsCallback(beacons)

PropertyTypeDefinition
beaconsArrayList of current beacon regions.

beaconUUIDCallback(status)

PropertyTypeDefinition
statusStringBeacon global UUID setup.

Geofence module

Methods

(static) geofenceEnabled(callback)

Query if geofences are enabled or disabled.

ParameterTypeDefinition
callbackgeofenceEnabledCallbackResponse callback.

(static) geofencesNear(callback, latitude, longitude, radius)

ParameterTypeDefinition
callbackgeofencesNearCallbackCallback data will be provided to
latitudedoubleLatitude of center of area
longitudedoubleLongitude of center of area
radiusdoubleRadius of area

(static) setGeofenceEnterCallback(callback)

Set callback for entering geofences.

ParameterTypeDefinition
callbackgeofenceCallbackCallback executed when geofences are entered.

(static) setGeofenceExitCallback(callback)

Set callback for exiting geofences.

ParameterTypeDefinition
callbackgeofenceCallbackCallback executed when geofences are exited.

Type definitions

Geofence

PropertyTypeDefinition
latitudedoubleLatitude of center of geofence.
longitudedoubleLongitude of center of geofence.
radiusdoubleRadius of geofence in meters.
locationIdStringUnique location identifier.

geofenceCallback(geofence)

PropertyTypeDefinition
geofenceGeofenceGeofence entered or exited.

geofenceEnabledCallback(status)

PropertyTypeDefinition
statusbooleantrue if geofences are enabled, false otherwise.

geofencesNearCallback(geofences)

PropertyTypeDefinition
geofencesArrayList of geofences

Related pages