Leveraging OkVerify's foreground service

OkVerify's foreground service improves the reliability and stability of verification signals coming from your user's Android device. Here's how to use it

Due to the Background Execution Limits introduced in Android 8 as well as restrictions imposed by some device manufacturers its become increasingly difficult to determine accurate and timely verification signals within android applications. In order to ensure reliability of these verification signals, the library comes with an opt-in foreground service that you can leverage to decrease the amount of time it takes to verify an address.

Starting the foreground service

Configure a notification that'll be used to start the service. If you followed the previous guide, this should already be setup in your index.js file

  channelId: 'okhi',
  channelDescription: 'OkHi verification alerts',
  channelName: 'OkHi Verification',
  title: 'Verification in progress',
    "We're currently verifying your address, you can ignore this notification",
  notificationId: 1,
  notificationRequestCode: 2

After successfully starting verification on an address, call the startForegroundService function available in the @okhi/react-native-okverify library

import { startVerification, startForegroundService } from '@okhi/react-native-okverify';

// Pass success response from OkCollect to startVerification function to start the verification process
const locationId = await startVerification(response);
const startedForegroundService = await startForegroundService(); // returns true || false indicating success of the process 

At this point a persistent notification will be shown to the user, signalling that the foreground service has indeed started successfully

Stopping the foreground service

Stopping the service is easy, simply make a call to the stopForegroundService function

import { stopForegroundService } from '@okhi/react-native-okverify'
// stops the running foreground service
const stoppedForeground = await stopForegroundService();

Stopping the foreground service does not stop verification of that address, the library will continue to use background services in order to obtain verification signals.

Determining whether the foreground service is running

You can make a call to the isForegroundServiceRunning function to determine whether a foreground service is present and running

import { isForegroundServiceRunning } from '@okhi/react-native-okverify'
// stops the running foreground service
const serviceRunning = await isForegroundServiceRunning();

Be sure to checkout our best practices doc for more information on foreground services

Last updated