Skip to main content

Overview

Hawcx SDK delivers revolutionary Smart Connect technology - the most intuitive passwordless authentication ever created for iOS applications. Smart Connect intelligently handles both sign up and sign in through a single, unified interface, eliminating decision fatigue while maintaining enterprise-grade security.

Smart Connect Technology

One-click intelligent authentication that automatically determines user context

Contextual Intelligence

No more “Sign Up” vs “Sign In” confusion - just one smart entry point

Seamless Cross-Platform

Smart Connect maintains user context across all devices and platforms

Web Login Approval

Allow users to approve web logins from their mobile device

Enterprise-Grade Security

Revolutionary security with consumer-grade simplicity

Architecture

Quick Start

1

Installation

  • Swift Package Manager
  • Manual
dependencies: [
    .package(url: "https://github.com/hawcx/hawcx_ios_sdk", .upToNextMajor(from: "4.0.0"))
]
Or add it directly in Xcode:
  1. Select File > Add Packages…
  2. Enter the package URL: https://github.com/hawcx/hawcx_ios_sdk
  3. Select “Up to Next Major Version” with version “4.0.0”
  4. Click “Add Package”
2

Initialize SDK

import HawcxFramework

// Initialize with your project API key
let hawcxSDK = HawcxSDK(projectApiKey: "YOUR_API_KEY")
3

Implement Smart Connect authentication:

Core Features

  • Implementation
  • SwiftUI Example
The revolutionary V4 SDK featuring Hawcx Smart Connect provides intelligent one-click authentication that automatically handles everything:What Smart Connect Does Automatically:
  • Intelligent User Recognition: Automatically detects if user is new or existing
  • Contextual Device Awareness: Knows if device is registered or new
  • Seamless Flow Management: Guides new users through verification, gives existing users instant access
  • Unified Experience: Single entry point - no more “Sign Up” vs “Sign In” confusion
  • Secure OTP Delivery: Sends verification codes only when needed
  • Advanced Cryptography: Manages all security operations transparently
  • Secure Token Storage: Stores credentials safely in iOS Keychain
  • Complete Authentication Intelligence: Handles the entire flow behind one smart button
SDK Methods:
  • authenticateV4(userid: String, callback: AuthV4Callback) - Initiates Smart Connect flow
  • submitOtpV4(otp: String) - Submits OTP for verification when needed
SDK Callbacks (AuthV4Callback protocol):
  • onOtpRequired() - Called when new user/device verification is needed
  • onAuthSuccess(accessToken: String?, refreshToken: String?, isLoginFlow: Bool) - Called on successful authentication
  • onError(errorCode: AuthV4ErrorCode, errorMessage: String) - Called when errors occur
  • Implementation
  • SwiftUI Example
Web login enables cross-platform authentication where users can log into your web application using their mobile device with Smart Connect intelligence.Use Case:
  • Your application has both web and mobile versions using Hawcx Smart Connect SDK
  • User visits your web app and initiates login
  • Web app displays a QR code (generated using Hawcx Web SDK with Smart Connect)
  • User scans QR code with mobile app
  • Mobile app shows login session details (browser, location, IP)
  • User approves the login from mobile
  • Web app automatically logs the user in with Smart Connect
What the SDK Does Automatically:
  • Validates PIN with backend
  • Retrieves and stores session details (browser, location, IP)
  • Manages web token for approval
  • Sends approval to complete web login
SDK Methods:
  • webLogin(pin: String, callback: WebLoginCallback) - Validates PIN from QR code
  • webApprove(token: String, callback: WebLoginCallback) - Approves web login session
SDK Callbacks (WebLoginCallback protocol):
  • onSuccess() - Called when operation succeeds
  • showError(webLoginErrorCode: WebLoginErrorCode, errorMessage: String) - Called on error
SDK Storage:
  • Saves web_token to UserDefaults after successful PIN validation
  • Saves sessionDetails with browser/location info to UserDefaults
  • Implementation
  • SwiftUI Example
The SDK works seamlessly with iOS biometric authentication and Smart Connect. You implement Face ID/Touch ID verification, then call the SDK’s Smart Connect authentication method:What You Implement:
  • Face ID/Touch ID prompt and verification
  • Biometric availability checks
  • Biometric preference storage
What the SDK Provides:
  • getLastLoggedInUser() to retrieve the last authenticated user
  • Smart Connect authenticateV4() for intelligent passwordless login after biometric success
  • Automatic handling of known device login (no OTP required)
Your Implementation:
  1. Check biometric availability using LAContext
  2. Perform biometric authentication
  3. On success, call SDK’s Smart Connect authenticateV4() method
  • Implementation
  • SwiftUI Example
What the SDK Manages:
  • JWT tokens (access & refresh) in iOS Keychain
  • Device registration keys in iOS Keychain
  • Last logged-in user identifier
  • Secure cleanup of credentials
SDK Methods:

clearSessionTokens(forUser: String)

Purpose: Standard logout functionality
What it does:
  • Removes JWT access and refresh tokens from Keychain
  • Preserves device registration (Er1r2 and persistent device token)
  • User can log back in without OTP verification
  • Device remains trusted
When to use:
  • Standard “Log Out” button functionality
  • Switching between accounts on same device
  • Temporary sign out
Example:
func logoutCurrentUser() {
    let userId = getCurrentUserId()
    sdk.clearSessionTokens(forUser: userId)
    // User will use Smart Connect but no OTP needed
    navigateToLoginScreen()
}

clearUserKeychainData(forUser: String) ⚠️

Purpose: Complete device removal
What it does:
  • Removes ALL user data from Keychain:
  • JWT tokens (access & refresh)
  • Device registration keys (Er1r2)
  • Persistent device token
  • All cryptographic material
  • User will need OTP to use this device again
  • Device is no longer trusted
When to use:
  • “Remove this device” functionality
  • Security breach response
  • Before selling/giving away device
  • Complete account removal
⚠️ WARNING: This is destructive! Do NOT use for standard logout.Example:
func removeDeviceCompletely() {
    let userId = getCurrentUserId()
    // Confirm with user first!
    showConfirmationDialog("Remove this device?") { confirmed in
        if confirmed {
            sdk.clearUserKeychainData(forUser: userId)
            // Smart Connect will require OTP next time
            navigateToLoginScreen()
        }
    }
}

getLastLoggedInUser() -> String

Purpose: UI convenience for Smart Connect screen
What it returns:
  • Email/identifier of last successfully authenticated user
  • Empty string if no user has logged in
When to use:
  • Pre-filling email field on Smart Connect screen
  • Enabling biometric login for returning users
  • Showing “Welcome back, [email]” messages
Example:
override func viewDidLoad() {
    super.viewDidLoad()
    
    // Pre-fill email field
    let lastUser = sdk.getLastLoggedInUser()
    if !lastUser.isEmpty {
        emailTextField.text = lastUser
        
        // Check if biometrics enabled for this user
        if isBiometricEnabled(for: lastUser) {
            showBiometricLoginButton()
        }
    }
}

clearLastLoggedInUser()

Purpose: Clear the UI pre-fill record
What it does:
  • Only removes the “last user” marker
  • Does NOT affect authentication state
  • Does NOT remove any tokens or keys
  • Next app launch won’t pre-fill email
When to use:
  • “Switch Account” functionality
  • Privacy mode where email shouldn’t be shown
  • App reset (keeping users logged in)
Example:
func switchToNewAccount() {
    // Clear pre-fill but keep current user logged in
    sdk.clearLastLoggedInUser()
    
    // Show fresh Smart Connect screen
    presentSmartConnectScreen(preFillEmail: false)
}

Understanding the Difference

ActionMethod to UseUser ExperienceOTP Required?
Log OutclearSessionTokens()Must use Smart Connect again❌ No
Remove DeviceclearUserKeychainData()Device registration lost✅ Yes
Hide Email Pre-fillclearLastLoggedInUser()No change to authN/A
Check Last UsergetLastLoggedInUser()Shows last emailN/A
  • Implementation
  • SwiftUI Example
The SDK provides detailed error codes through the callback. Here’s how to handle them:SDK Provides:
  • AuthV4ErrorCode enum with specific error cases
  • Human-readable error messages
  • Error details in callback
You Implement:
  • Error UI (alerts, inline messages)
  • Retry logic
  • Navigation based on error type

Troubleshooting

Symptoms:
  • networkError returned in callback
  • Smart Connect doesn’t proceed
Solutions:
  1. Check internet connectivity
  2. Verify API key is correct
  3. Ensure no firewall/proxy blocking
  4. Implement retry logic with exponential backoff
func retrySmartConnect(attempts: Int = 3) {
    var currentAttempt = 0
    
    func attempt() {
        sdk.authenticateV4(userid: email, callback: self)
    }
    
    // In error callback
    if errorCode == .networkError && currentAttempt < attempts {
        currentAttempt += 1
        DispatchQueue.main.asyncAfter(deadline: .now() + Double(currentAttempt * 2)) {
            attempt()
        }
    }
}
Symptoms:
  • otpVerificationFailed error
  • User cannot proceed past OTP screen
Solutions:
  1. Ensure OTP is exactly 6 digits
  2. Check if OTP expired (5 minute validity)
  3. Enable auto-fill for better UX:
otpTextField.textContentType = .oneTimeCode
Symptoms:
  • Biometric prompt doesn’t appear
  • Authentication fails immediately
Solutions:
  1. Add to Info.plist:
<key>NSFaceIDUsageDescription</key>
<string>Authenticate with Face ID for secure access</string>
  1. Check biometric availability:
let context = LAContext()
var error: NSError?

if !context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
    print("Biometrics not available: \(error?.localizedDescription ?? "Unknown")")
}
  1. Handle specific biometric errors:
if let error = error as? LAError {
    switch error.code {
    case .biometryNotEnrolled:
        print("User hasn't set up biometrics")
    case .biometryLockout:
        print("Too many failed attempts")
    case .biometryNotAvailable:
        print("Device doesn't support biometrics")
    default:
        print("Other error: \(error)")
    }
}
Symptoms:
  • keychainSaveFailed errors
  • Login state not persisted
Solutions:
  1. Ensure app has keychain entitlement
  2. Check if device is locked during keychain access
  3. Test keychain availability:
let testQuery: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrAccount as String: "test",
    kSecValueData as String: "test".data(using: .utf8)!
]

let status = SecItemAdd(testQuery as CFDictionary, nil)
if status == errSecInteractionNotAllowed {
    print("Device is locked - keychain not accessible")
}

// Clean up
SecItemDelete(testQuery as CFDictionary)

Error Codes

  • AuthV4ErrorCode
  • WebLoginErrorCode
Error CodeDescription
networkErrorNetwork connectivity issue or request timeout
unknownErrorUnexpected error occurred
invalidInputInvalid email or userid format
keychainSaveFailedFailed to save data to iOS Keychain
clientCryptoErrorCryptographic operation failed on device
fingerprintErrorFailed to generate device fingerprint
authInitFailedAuthentication initialization failed
otpVerificationFailedInvalid or expired OTP
deviceVerificationFailedDevice registration verification failed
cipherVerificationFailedLogin cipher verification failed
internalStateErrorSDK internal state corruption
missingDeviceTokenSessionSession token missing during flow
missingEr1r2ForRegistrationCryptographic keys missing
missingCryptoForLoginDevice keys not found for login
missingPersistentDeviceTokenDevice token not found

Support

I