Acoustic Mobile Push Location Plugin
Requirements
- Acoustic Mobile Push Plugin (react-native-acoustic-mobile-push)
Description
This module provides the infrastructure to support geofences and beacons. Note that other plugins are required to fully support geofences and beacons.
Installation
If your app is using React Native v0.60 or later and are using the AndroidX libraries instead of the Android Support libraries, set the following command line variable:
export ANDROID_X=1
Then install as normal
Installation
npm install --save <sdk folder>/plugins/react-native-acoustic-mobile-push-location
Post Installation Steps
Link the plugin with
react-native link react-native-acoustic-mobile-push-location
Android Support If your app is using React Native v0.60 or later and are using the AndroidX libraries instead of the Android Support libraries. You will need to adjust the imports in RNAcousticMobilePushLocationModule.java by removing:
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
and adding:
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
iOS Support
Please replace the placeholder location usage descriptions in info.plist in the NSLocationWhenInUseUsageDescription, NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription keys. These values help inform your users how you're going to respectfully use the access.
Module API
callback
)
locationStatus(Description
This method can be used to determine if the application has permission to use location.
Parameters
callback
is executed with a single parameter value with one of the following values:
-
"denied"
- Android/iOS user disallowed location use -
"delayed"
- iOS only value for not yet determined -
"always"
- Android permission granted / iOS always allowed permission granted -
"restricted"
- iOS restricted use permission granted -
"enabled"
- iOS when in use permission granted -
"disabled"
- Android/iOS disabled in MceConfig.json file
Example
import {RNAcousticMobilePushLocation} from 'NativeModules';
RNAcousticMobilePushLocation.locationStatus((status)=>{
if(status == "denied") {
// Do not use location features
} else if(status == "delayed") {
// Do not use location features yet
} else if(status == "always") {
// Can use location features in foreground or background
} else if(status == "restricted") {
// Restricted use of location features
} else if(status == "enabled") {
// Can use location features in foreground only
} else if(status == "disabled") {
// Location features are not enabled in config file
}
});
syncLocations()
Description
Request geofence and beacon sync with server. Use DownloadedLocations
event to be informed of when this is finished.
Example
import {RNAcousticMobilePushLocation} from 'NativeModules';
RNAcousticMobilePushLocation.syncLocations();
enableLocation()
Description
Turns on location support when delayed in the MceConfig.json file.
Example
MceConfig.json
{
...
"location": {"autoInitialize": false }
...
}
In Application
import {RNAcousticMobilePushLocation} from 'NativeModules';
// After user uses a feature that would require location features
RNAcousticMobilePushLocation.enableLocation();
Events Emitted
DownloadedLocations
Description
This event is emmited when the geofence/beacon list is updated from the server.
Example
import {NativeEventEmitter} from 'react-native';
import {RNAcousticMobilePushLocation} from 'NativeModules';
const emitter = new NativeEventEmitter(RNAcousticMobilePushLocation);
emitter.addListener('DownloadedLocations', () => {
// May need to refresh geofence interface display
});