Installation
Adding Geofence Plugin
Add capacitor-moengage-geofence plugin to the capacitor project as shown below :
$npm install capacitor-moengage-geofence
Android Installation
Once you install the Flutter Plugin add MoEngage's native Android SDK dependency to the Android project of your application.
Navigate to android/app/build.gradle. Add the MoEngage Android SDK's dependency in the dependencies block.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation("com.moengage:geofence:$sdkVersion")
}
where $sdkVersion should be replaced by the latest version of the MoEngage Geofence SDK
iOS
In the case of iOS, the native dependency is part of the Geofence Cordova SDK itself, so there is no need to include any additional dependency for supporting Geofence.
Configuration
Start Geofence Monitoring
After integrating the geofence package call startGeofenceMonitoring() method to initiate the geofence module, this will fetch the geofences around the current location of the user. Please take a look at the iOS doc and Android doc for more information on Geofence. By default, the geofence feature is not enabled. You need to call the startGeofenceMonitoring() to receive location-triggered push messages.
import { MoECapacitorGeofence } from 'capacitor-moengage-geofence';
MoECapacitorGeofence.startGeofenceMonitoring({ appId: "YOUR_Workspace_ID" });
Stop Geofence Monitoring
If you want to stop the geofence monitoring or feature use the stopGeofenceMonitoring() API. This API will remove the existing geofences.
import { MoECapacitorGeofence } from 'capacitor-moengage-geofence';
MoECapacitorGeofence.stopGeofenceMonitoring({ appId: "YOUR_Workspace_ID" });