React Native Library
The OkHi react native library will enable you to start collecting and verifying your user's addresses.
Prerequisites
OkHi Client Key and Branch Id
First you need to obtain your OkHi client key and branch ID. You can get these by signing up here.
Installation
Install the OkHi React Native library
Configure your app
Android
Add the following permissions to your AndroidManifest.xml
located under android/app/src/main/AndroidManifest.xml
If you're targeting Android versions >= 8 and you're using the OkVerify library you need to make sure your users select on "Allow always" when granting permissions otherwise the verification process won't work.
All OkHi react-native libraries target Android devices >= SDK 21. Make sure you're targeting at least the same by modifying your android/build.gradle
file
iOS
Enable background mode in your application.
OkHi obtains verification signals in the background, to enable this make sure to add "Location updates" and "Background fetch" to your Background Modes under Signing & Capabilities of your target.
All OkHi react-native libraries target IOS devices >= 12. Make sure you're targeting at least the same by modifying both your Podfile and deployment target.
Podile located under: ios/Podfile
Add necessary permissions to your info.plist
file located under /ios/MyApp
Finally, install all required pods by running the following command in the ios
directory
Set up OkVerify in your AppDelegate file
Open your AppDelegate.mm
file located under ios/MyApp/AppDelegate.mm
and add the following lines
Initialization
Add the following initialization code to your index.js
file. Replace my_branch_id
and my_client_key
with the keys provided to you after sign up.
Create and verify addresses
fcmPushNotificationToken is an optional field for your user object. Learn more.
Customizing verification type parameters
OkCollect V1 introduces the ability to specify out of two types, the location the customer is at.
home
work
Ideally, you would ask your user to specify this during address creation and it helps our AI more efficiently and quickly verify an address.
Managing verification start requirements
For Addresses to be verified, the following requirements must be satisfied.
User grants background location permission on both Android / iOS
Location services must be turned on both Android / iOS
Google Play Services must be available on Android
Luckily the OkHi library has helper methods to assist you with these requirements.
The request
function will go ahead and requests for background location permission as well as activate any services that might be offline. If you'd like a much fine grain control over how permissions are requested please see the API reference.
Make sure to go over our best practices doc requirement to make sure your application meets Play Store and App Store guidelines for requesting for background location permission.
Leveraging OkVerify's Android 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.
The foreground service is started by default once verification of an address starts, but can also be started again if previously stopped using the startForegroundService
function
Stopping the foreground service
Stopping the service is easy, simply make a call to the stopForegroundService
function
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
Customise notification icon & color
You can specify a custom default icon and a custom default color by adding these lines inside the application
tag to set the custom default icon and custom color. You'll need to have already created the icon resource in your android application. Icon assets can be created by following these steps
Recipes
Starting verification without using OkHiLocationManager
If your user created an address with OkHi and you have a valid locationId, pair of coordinates and user information such as a phone number, you can start verification without using the OkHiLocationManagerResponse object
Customizing OkHiLocationManager
Its possible to completely transform the default apperance of OkHiLocationManager to better match your brand by providing values to the theme
prop
FAQs
Building with pro-guard enabled
If you have minifyEnabled
set to true
in your build.gradle
file located android/app/build.gradle
, you'll need to modify your proguard-rules.pro
file, located android/app/proguard-rules.pro
as shown bellow to include classes required by the library to run.
Next steps
Checkout the API reference
Build a webhook endpoint to receive OkHi address verification scores.
Last updated