In your AppDelegate.swift file configure the OkHi Auth object with your client key and branch ID. Make sure to also setup your app's context with meta data about your application
importOkCoreimportOkCollect 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:"<my_branch_id>", clientKey:"<my_client_key>", environment: Environment.sandbox, // make sure to change this to prod when you're ready to go live 🚀 appContext: okHiAppContext) OkHiCollect.initialize(with: okHiAuth)returntrue}
Start creating addresses
importUIKitimportOkCoreimportOkCollectclassViewController:UIViewController {privatelet okCollect =OkHiCollect()// initialise the OkCollect class private let okhiLocationService = OkHiLocationService() // optionally use the OkHiLocationService to manage location permissions
overridefuncviewDidLoad() { super.viewDidLoad() okCollect.delegate = self // set your view controller as an OkCollect delegate okhiLocationService.delegate = self // set your view controller as an OkHiLocationService delegate }funcshowMessage(title: String, message: String) {let alert =UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title:"Ok", style: .default, handler:nil)) self.present(alert, animated:true, completion:nil) }@IBActionfunconButtonPress(_sender: UIButton) {if!okhiLocationService.isLocationServicesAvailable() { // check whether location services is turned on showMessage(title: "Turn on location services", message: "Location services are required to create and verify an address.")
return }if okhiLocationService.isLocationPermissionGranted() { // check for location permissionlaunchOkCollect() } else { okhiLocationService.requestLocationPermission(withBackgroundLocationPermission: true) // requests for background location permission if you're going to use OkVerify, set false if not
} }funclaunchOkCollect() { let okHiTheme = OkHiTheme().with(logoUrl: "https://cdn.okhi.co/icon.png").with(appBarColor: "#ba0c2f").with(appName: "OkHi")
let okHiConfig =OkHiConfig().enableStreetView().enableAppBar()guardlet vc = okCollect.viewController(with: okHiUser, okHiTheme: okHiTheme, okHiConfig: okHiConfig)else {return } self.present(vc, animated:true, completion:nil) }}extensionViewController:OkCollectWebviewDelegate {funccollect(didEncounterErrorerror: OkHiError) {showMessage(title:"Error: \(error.code)", message: error.message) }funccollect(didSelectAddressuser: OkHiUser, location: OkHiLocation) {// your magic goes here, user has created an address ✨ }}extensionViewController:OkHiLocationServiceDelegate { func okHiLocationService(locationService: OkHiLocationService, didChangeLocationPermissionStatus locationPermissionType: LocationPermissionType, result: Bool) {
if locationPermissionType == .always && result { // check whether location permission was grantedlaunchOkCollect() } }}
Whenever a user's OkHi address is created or used an SMS is sent to them notifying them of this usage
Whereas OkCollect does provide ways to customize the look and feel of the address creation process as well as alter some of the in built functionality. Due to accessibility concerns, the product will work with select brand colors that provide enough contrast to the text being rendered.