Flutter Library
The OkHi Flutter 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 Flutter library by running the bellow command in your flutter project directory
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 20. Make sure you're targeting at least the same by modifying your android/app/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 flutter libraries target ios devices >= 12. Make sure you're targeting at-least the same by modifying your both your Podfile and deployment target.
Podile located under: ios/Podfile
Add necessary permissions to your info.plist
file located under /ios/Runner/info.plist
Install all required pods by running the following command in the ios
directory
Set up OkHi in your AppDelegate file
Open your AppDelegate file located under ios/Runner/AppDelegate.swift
and add in the following
Usage
Initialization
Add the following initialization code to your main.dart
file. Replace my_branch_id
and my_client_key
with the keys provided to you after sign up.
Create and verify addresses
Customizing address type parameters
OkCollect V1 introduces the ability to specify out of two types, the location the customer is at.
withHomeAddressType
withWorkAddressType
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 OkHi.canStartVerification
method will go ahead and request for background location permission as well as activate any services that might be offline. If you'd like much more fine-grain control over location permission, see the API reference for more options.
Make sure to go over our best practice doc requirement to make sure your application meets Play Store and App Store guidelines for requesting background location permission.
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 the 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 as part of the initialization.
The foreground service is started by default once verification of an address starts, but can also be started again if previously stopped using the OkHi.startForegroundService
method.
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 in the AndroidManifest.xml
located under android/app/src/main/AndroidManifest
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
It is possible to completely transform the default appearance 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
Review the API reference
Build a webhook endpoint to receive OkHi address verification scores.
Last updated