Core Usage


1. User Session

Identify the user after login for WebView and server-sent events (SSE); log out on sign-out.

// After login
KLP.shared.setUser(
    userId: "unique_user_id",
    accessToken: "access_token",
    refreshToken: "refresh_token", // optional
    nameInitials: "GY" // optional, shown as avatar in webview
)

// On logout
KLP.shared.logout()
  • setUser and logout never throw; if the SDK is not initialized yet, they safely no-op so the host app login/logout flow is not interrupted.
  • Session data is stored securely on the device.

2. Launching the Loyalty Screen (WebView)

// Home screen
try KLP.shared.launch(from: self)

// A specific path (e.g. rewards)
try KLP.shared.launch(from: self, path: "rewards")

Leading and trailing / in the path value are optional; the SDK handles concatenation.

Launching Simulation Mode

Simulation mode opens a separate WebView from the loyalty/gamification screen:

try KLP.shared.launchSimulation(from: self)

The SDK still sends the secure session headers, current user ID (cid), app language and theme to the simulation WebView. During development the simulation WebView points to http://localhost:8888; domain checks are already enforced so this can be switched to a production HTTPS domain by the SDK team without changing app integration code.