Comment on page
iOS Guide
Learn about OkHi's integration for verifying addresses.

The OkHi libraries are fully documented and compatible with apps supporting iOS 12 and above. You would require the latest versions of Xcode & Swift
Swift Package Manager
CocoaPods
To install the library:
1 In Xcode, select File > Add Packages... and enter the following URL as the repository URL
https://github.com/OkHi/ios-okhi
2. Select the default main branch
3. Add the OkHi library package product to the target of your app
pod init
3. Add
pod 'OkHi'
to your Podfile
and update iOS target to 12 and above as follows. Check for the latest release here https://github.com/OkHi/ios-okhi/releasesplatform :ios, '12.0'
target 'MyAwesomeApp' do
pod 'OkHi', '~> 1.9.9'
end
4. Run the following command:
pod install
5. Don’t forget to use the
.xcworkspace
file to open your project in Xcode, instead of the .xcodeproj
file, from here on out.Address verification requires
AlwaysAndWhenInUseUsage
location to verify the user's addressTo satisfy these requirements add the following to your info.plist file and provide a useful description as to why your application needs access to the user's location.
<key>NSLocationWhenInUseUsageDescription</key>
<string>String that explains why you need this permission</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>String that explains why you need this permission</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>String that explains why you need this permission</string>
OkVerify obtains and transmits verification signals in the background, to enable this make sure to add "Location updates" and "Background fetch" at Background Modes under Signing & Capabilities of your target

In your
AppDelegate.swift
file configure the OkHi Auth object with your client key and branch ID. Sign up here. Make sure to also setup your app's context with meta data about your applicationimport OkHi
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let okHiAppContext = OkHiAppContext().withAppMeta(name: "My Awesome App", version: "1.0.0", build: "1")
let okHiAuth = OkHiAuth(
branchId: "", // your branch ID
clientKey: "", // your client key
environment: OkHi.Environment.prod,
appContext: okHiAppContext
)
OkCollect.initialize(with: okHiAuth)
OkVerify.initialize(with: okHiAuth, launchOptions: launchOptions)
return true
}
Add a button to your UI that would enable launching of OkHi address collection tool.
We recommend that you persist the verification state of the user in your app local storage. This state can be used to ensure that a user may only verify a predefined number of addresses. Usually one address for most use cases.
For OkVerify to work correctly "Always" Location permission needs to be granted by your users. The library provides the
requestBackgroundLocationPermission
method that enables you to manage these permission requirements as shown below.1
import UIKit
2
import OkHi
3
import CoreLocation
4
5
class ViewController: UIViewController {
6
private let okCollect = OkCollect()
7
private let okVerify = OkVerify()
8
9
override func viewDidLoad() {
10
super.viewDidLoad()
11
// Do any additional setup after loading the view.
12
okCollect.delegate = self
13
okVerify.delegate = self
14
}
15
16
@IBAction func onButtonPress(_ sender: UIButton) {
17
if okVerify.isLocationServicesEnabled() {
18
if okVerify.isBackgroundLocationPermissionGranted() {
19
startAddressCreation()
20
} else {
21
// TODO: Show location permissions primer here
22
okVerify.requestBackgroundLocationPermission()
23
}
24
}
25
}
26
27
func startAddressCreation() {
28
let okHiTheme = OkHiTheme()
29
.with(logoUrl: "https://cdn.okhi.co/icon.png")
30
.with(appBarColor: "#ba0c2f")
31
.with(appName: "OkHi")
32
let okHiConfig = OkHiConfig().enableStreetView().enableAppBar()
33
guard let vc = okCollect.viewController(
34
with: OkHiUser(phoneNumber: "+234xxxxx") // It is important to provide your actual phone number, as a message will be sent to this number
35
.with(firstName: "Gift")
36
.with(lastName: "Moore")
37
.with(email: "[email protected]"),
38
okHiTheme: okHiTheme,
39
okHiConfig: okHiConfig
40
) else {
41
return
42
}
43
self.present(vc, animated: true, completion: nil)
44
}
45
46
func startAddressVerification(user: OkHiUser, location: OkHiLocation) {
47
okVerify.startAddressVerification(user: user, location: location)
48
// TODO persist address verification state in app local database store
49
}
50
51
}
52
53
extension ViewController: OkCollectDelegate {
54
func collect(didEncounterError error: OkHiError) {
55
// handle error
56
debugPrint(error)
57
}
58
59
func collect(didSelectAddress user: OkHiUser, location: OkHiLocation) {
60
startAddressVerification(user: user, location: location)
61
}
62
63
64
}
65
66
extension ViewController: OkVerifyDelegate {
67
func verify(_ okverify: OkVerify, didChangeLocationPermissionStatus requestType: OkVerifyLocationPermissionRequestType, status: Bool) {
68
if requestType == .always && status {
69
startAddressCreation()
70
}
71
}
72
73
func verify(_ okverify: OkVerify, didInitialize result: Bool) {
74
print("initialized successfully")
75
}
76
77
func verify(_ okverify: OkVerify, didEncounterError error: OkVerifyError) {
78
debugPrint(error)
79
}
80
81
func verify(_ okverify: OkVerify, didStartAddressVerificationFor locationId: String) {
82
print("started verification for: \(locationId)")
83
}
84
85
func verify(_ okverify: OkVerify, didStopVerificationFor locationId: String) {
86
print("stopped verification for: \(locationId)")
87
}
88
89
func verify(_ okverify: OkVerify, didUpdateLocationPermissionStatus status: CLAuthorizationStatus) {
90
// called on each status change
91
print("location permission status updated")
92
}
93
94
func verify(_ okverify: OkVerify, didUpdateNotificationPermissionStatus status: Bool) {
95
print("push notification permission status updated")
96
}
97
}
98
Test
Verification has started successfully:
When you simulate a change in the location of the device, you should see the GPS icon lighting up at the top of the screen
Common issues:
- if background location permission is not granted, verification will not start
Here's a sample address payload that the client would get on successful address collection:
{
"user": {
"id": "B5QgvjE8WC",
"phone": "+234xxxx",
"firstName": "Gift",
"lastName": "Moore"
},
"location": {
"id": "8F0yPK1Zdj",
"lat": 6.442849499999999,
"lon": 3.424421,
"plusCode": "6FR5CCVF+4Q",
"propertyName": "10",
"streetName": "Raymond Njoku Street",
"title": "Raymond Njoku Street",
"subtitle": "10",
"url": "https://okhi.me/8F0yPK1Zdj",
"streetViewPanoId": "ufxEWf-zpKLcTxIe04o6Bg",
"streetViewPanoUrl": "https://maps.googleapis.com/maps/api/streetview?size=640x640&fov=45&location=6.44275037195316%2C3.424513218681455&heading=321.4785708568841&pitch=-9.5945875978788",
"userId": "B5QgvjE8WC",
"displayTitle": "10, Raymond Njoku Street",
"country": "Nigeria",
"state": "Lagos",
"city": "Eti-Osa",
"countryCode": "ng"
}
}
Create a secure endpoint on your server that your app can use to pass address details to your server. Remember to handle corner cases such as, address updates, multiple addresses if your app supports it.
Node
1
//Secure new address endpoint
2
app.post("/users/addresses", async (req) => {
3
const { user, location } = req.body;
4
const { id, firstName, lastName, phone } = user;
5
const {
6
id: locationId, displayTitle, title, subtitle, country, state, city, countryCode, lat, lon, plusCode, propertyName, streetName, url, streetViewPanoId, streetViewPanoUrl
7
} = location;
8
console.log(user, location);
9
// Store the location.id. Used to match webhook updates
10
return;
11
});
OkHi sends verification status updates over a few days while verification is on going. Follow the webhook guide to setup a webhook and receive these verification status updates and run actions such as upgrading a user's KYC level.
Create a secure endpoint to enable your app to retrieve address details, including the verification status received from the webhook
Node
// Secure address retrieval endpoint
app.get("/users/addresses", (req) => {
// Get data from db. Example result:
const dbResult = {
"id": "8F0yPK1Zdj",
"status": "verified",
"displayTitle": "10, Raymond Njoku Street",
"title": "Raymond Njoku Street",
"subtitle": "10",
"country": "Nigeria",
"state": "Lagos",
"city": "Eti-Osa",
"countryCode": "ng",
}
return dbResult;
});
Show the resulting address details and status on the address page in your app.

Title | Scenario | How to test |
---|---|---|
Create an address | Address creation succeeds and verification is initiated | Launch OkHi's address manager via the button you created and create an address.
A sticky notification appears on android. |
Dashboard | Check OkDash, you should see a list of all the addresses created.
It takes ~3min for addresses to show up on OkDash | |
Proof of address | When an address is verified, the webhook receives the status update and the app shows the correct verification status. A proof of address certificate is made available on OkDash. | Install your app on your personal device that you move around with and create your home address. Check okDash in 3 days for your proof of address certificate once your address has been verified. |
Business logic | When an address is verified or not, the correct business logic is applied successfully. | Conduct a comprehensive test with multiple users, wherein they create various addresses to observe diverse outcomes. These outcomes may include successful creation of home addresses, entering incorrect addresses, refusing to grant necessary location permissions, or uninstalling the app immediately after initiating the address verification process, among other scenarios. |
Create your custom location permissions primer to educate your user on the requirement for location permissions. Make sure to follow our design best practices to ensure you meet the Google Play store and AppStore requirements.
Its possible to completely transform the default appearance of OkHiLocationManager to better match your brand by providing values to the
theme
prop
Its possible to completely transform the default apperance of OkHiLocationManager to better match your brand by providing values to the
okHiTheme
prop1
let okHiTheme = OkHiTheme()
2
.with(logoUrl: "https://cdn.okhi.co/icon.png")
3
.with(appBarColor: "#ba0c2f")
4
.with(appName: "OkHi")
5
let okHiConfig = OkHiConfig().enableStreetView().enableAppBar()
6
guard let vc = okCollect.viewController(with: OkHiUser(
7
phoneNumber: "+234xxxxx"
8
),
9
okHiTheme: okHiTheme,
10
okHiConfig: okHiConfig
11
) else {
12
return
13
}
14
self.present(vc, animated: true, completion: nil)
You may turn off either of the OkHi address types. This is to allow your users to create either home or work addresses to better suit your use-case. By default both address types are on.
let okHiConfig = OkHiConfig().enableStreetView().enableAppBar().withAddressTypes(work: true, home: false)
Notify us that you'd like to cut a production build so we can supply production credentials.
Submitting an app to App Store that has background location permissions has a few extra requirements. Follow these guide to know what to expect and how to handle the extra requirements:
Last modified 2mo ago