Configuring Client ID for iOS

Open your project’s Info.plist and follow the steps below. Once complete, your Info.plist should resemble the sample shown here:

  1. Copy your client_id from the ZenKey service provider portal dashboard.
  2. Open your application’s Info.plist. Add a ZenKeyClientId key, then paste your client_id as the string value:
    <key>ZenKeyClientId</key>
    <string>{client_id}</string>
  1. Add CFBundleURLTypes — the list of URL schemes supported by the app — as a key:
    <key>CFBundleURLTypes</key>     

After adding this, Xcode will create an array with a "Type 0" dictionary containing a CFBundleURLName key.

  1. Add CFBundleTypeRole and CFBundleURLSchemes to the "Type 0" dictionary. If your project already has a CFBundleURLTypes key with an existing Type dictionary, this new data may still be added at any index.

  2. Add your client_id a second time, also as a string, under CFBundleURLSchemes:

    <key>CFBundleURLSchemes</key>     
    <array>
    <string>{client_id}</string>
    </array>

Instantiate ZenKey

To use the ZenKey SDK within your application, instantiate ZenKey in the AppDelegate as follows:

import ZenKeySDK
...
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication,
     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        ZenKeyAppDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )

        // Perform additional application setup.

        return true
    }

Let the ZenKey SDK handle redirects

If your app does not use a SceneDelegate, use the following code in the AppDelegate:

   func application(_ app: UIApplication, 
            open url: URL, 
            options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
              if ZenKeyAppDelegate.shared.application(app, open: url, options: options) {
              return true
        }
        // Perform any other URL processing your app may need.
        return false
    }
}

If your app does use a SceneDelegate, insert the following code in the SceneDelegate instead:

import ZenKeySDK
...
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let _ = (scene as? UIWindowScene) else { return }

        ZenKeySceneDelegate.shared.scene(scene, willConnectTo: session, options: connectionOptions)
    }

    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        let unhandledContexts = ZenKeySceneDelegate.shared.scene(scene, openURLContexts: URLContexts)
        unhandledContexts.forEach { context in
            // Handle context
        }
    }
}

Did this page help you?