The OkHi libraries are fully documented and compatible with apps supporting iOS 12 and above. You would require the latest versions of Xcode & Swift.
To install the library:
1 In Xcode, select File > Add Packages... and enter the following URL as the repository URL
Copy
https://github.com/OkHi/ios-okhi
2. Select exact version 1.9.46
3. Add the OkHi library package product to the target of your app
If you haven’t already, install the latest version of CocoaPods.
2. If you don’t have an existing Podfile, run the following command at the root directory of your project, to create one:
pod init
3. Add pod 'OkHi' to your Podfile and update iOS target to 12 and above as follows.
platform :ios,'12.0'target 'MyAwesomeApp'do pod 'OkHi','~> 1.9.45'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.
Configuration
Permissions
Add the following permissions to your Info.plist located under the root directory of your iOS project.
<dict> <key>NSLocationAlwaysUsageDescription</key> <string>Grant to enable verifying your addresses.</string> <key>NSLocationWhenInUseUsageDescription</key> <string>Grant to enable creating addresses at your current location.</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>Grant to enable creating and verifying your addresses.</string></dict>
Background Modes
OkHi iOS library 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
Configure OkVerify
As part of verification it is crucial to obtain app usage information, to enable this call the onStart static method available in the OkVerify module whenever your app launches. We recommended calling it at your SceneDelegate's sceneDidBecomeActive method like so. The SceneDelegate file is located at the root of your iOS project.
importUIKitimportOkHiclassSceneDelegate:UIResponder, UIWindowSceneDelegate {funcsceneDidBecomeActive(_scene: UIScene) { OkVerify.onStart()// <- add this }}
Credentials
In your AppDelegate.swift file configure the OkHi Auth object with your clientKey and branchId. Sign up here. Make sure to also setup your app's context with meta data about your application
Always use your phone number or a phone number you own during testing as a message will be sent to this number after an address is created.
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.
If you'd like to only create the address and still obtain usage data that will help verification later, you can include the usage type as part of the config object that's passed to OkCollect
It's possible to have both physical and digital verification to run at the same time for a given address. Include both usage types as part of the array.
It's possible to create an address, obtain usage data that will help verification and initiate either physical and/or digital at a later time.
The example assumes:
You created an address using addressBook usage type. See here.
You've securely stored previous address information either on device or server and have access to the locationId obtained in the success response of okcollect.
Making it yours (Customise address creation experience)
It is possible to completely transform the default appearance of OkCollect to better match your brand by creating a okhiTheme object and passing it to OkCollect as shown bellow.
private let okHiTheme =OkHiTheme().with(logoUrl: "https://cdn.okhi.co/icon.png").with(appBarColor: "#333").with(appName: "OkHi")
Create home or work addresses
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)
Error handling
Both the OkCollectDelegate and OkVerifyDelegate have an didEncounterError method where you can handle errors. You have access to error.code and error.message which you can use to futher debug the address creation or verification process.
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:
On the client/app, within your onSucess handler you can access both user and address information which you can use to transit securely to your servers. See the API reference for complete list of properties on user and location.
consthandleOnSuccess=async (response:OkCollectSuccessResponse) => {console.log(response.user.id); // access user propertiesconsole.log(response.location.id); // access location propertiesawaitsendToServer(response.user,response.location) // send address info to your serverawaitresponse.startVerification(); // start verification}
Handling verification events
Once an address has been created and you've configured a webhook in the OkHi Customer Dashboard, you'll be able to receive updates regarding address verification in your backend, which you can use to enable certain services in your app. The OkHi Dashboard allows you to do much more; please see the full webhook documentation here.
Testing
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
When verification is initiated, the address shows up on OkHi 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.