Utilize the Smart Geofences API
On this page, you can find examples of how to register for real time smart geofence entry and exit event notifications, how to query the Sentiance SDK for the current smart geofences detection mode, as well as how to refresh the list of monitored smart geofences.
Listen to smart geofence entry/exit events
// Create an instance of the delegate that will handle the events.
private let smartGeofenceEventDelegate = MySmartGeofenceEventDelegate()
// Set the delegate on the Sentiance SDK. Note that the SDK holds a weak
// reference to this delegate.
Sentiance.shared.smartGeofenceEventsDelegate = smartGeofenceEventDelegate
// Define the delegate class that will handle the events.
class MySmartGeofenceEventDelegate: SmartGeofenceEventDelegate {
func onSmartGeofenceEvent(_ smartGeofenceEvent: SmartGeofenceEvent) {
// Handle the events here.
}
}import com.sentiance.sdk.smartgeofences.api.SmartGeofenceApi
SmartGeofenceApi.getInstance(mContext).setSmartGeofenceEventListener { event ->
// Handle the events here.
}To get smart geofence entry/exit event updates even when your app is in the background, place the following code inside your app's entrypoint index.js file. If you're only interested in these updates when your app is foregrounded, place this code inside the appropriate UI code instead.
import {addSmartGeofenceEventListener} from "@sentiance-react-native/smart-geofences";
// If you're subscribing to event updates only in the foreground, make sure
// to call subscription.remove() inside your component's componentWillUnmount() function
const subscription = addSmartGeofenceEventListener(smartGeofenceEvent => {
// Handle the events here.
});Create a background.dart file under your project's lib folder with the following code:
Add the following code, depending on your target platform.
For iOS, add the following to your app delegate class:
For Android, add this code to your custom application class:
If you're calling other APIs from the smart geofences SDK or other 3rd party plugin APIs inside your registerSmartGeofenceEventListener Dart function, then you need to register these plugins with the Sentiance SDK. See this for more details.
Refresh the list of monitored geofences
The SDK regularly refreshes the list of monitored geofences. You can request an immediate refresh as follows:
Get the current smart geofences detection mode
Last updated