Nx10 Logo
Docs

1. Initialisation

Bridging the data gap between the Host App and the Keyboard Extension.

The Data Handoff Flow

The Keyboard Extension operates blindly. It doesn't know who the user is or what your API key is. Your Host App must authenticate the user, gather their identifiers, and securely write them into the shared App Group UserDefaults.

Why passing Phone/Email is Best Practice

The LFM relies on longitudinal data to build an accurate emotional profile. While the DeviceId (identifierForVendor) is required, it will change if the user upgrades their iPhone. If you pass an optional Email or Phone Number into the configuration, the Nx10 backend can fuzzy-match the user when they get a new device, instantly restoring their predictive LFM profile rather than starting from scratch.

Step 1: Host App Setup

HostAppNX10Manager.swift
import Nx10Core

class HostAppNX10Manager {
    func configureKeyboard() {
        // 1. Define the parameters in the Host App
        let config = Nx10KeyboardConfig(
            apiKey: "sk_live_abc123",
            identifiers: Nx10Identifiers(
                deviceId: UIDevice.current.identifierForVendor?.uuidString ?? UUID().uuidString,
                email: "user@example.com", // Highly recommended for cross-device LFM matching
                phoneNumber: nil
            ),
            appGroupId: "group.com.mycompany.nx10" // CRITICAL: Your shared vault
        )

        // 2. The SDK securely writes this configuration into the shared App Group
        Nx10Core.shared.writeKeyboardConfig(config)
        
        print("Nx10 configuration ready. The keyboard will pick this up when launched.")
    }
}

Step 2: Keyboard Extension Boot

In your Keyboard Extension target, your primary view controller must inherit from Nx10KeyboardViewController (which wraps KeyboardKitPro). When it boots, it automatically looks inside the App Group, finds the credentials, and starts the telemetry session.

KeyboardViewController.swift
import UIKit
import Nx10Keyboard

class KeyboardViewController: Nx10KeyboardViewController {

    override func viewDidLoad() {
        // 1. Tell the keyboard which App Group vault to read the API Key and User ID from
        self.initializeNx10(appGroupId: "group.com.mycompany.nx10")
        
        super.viewDidLoad()
        
        // 2. The keyboard is now seamlessly collecting kinematics against the user's Device ID
    }
}