Skip to content

Alphyn Sdk Class

Main SDK class providing core functionality. All methods are static.

register()

  • Signature: static func register() throws
  • Description: Registers the SDK’s background tasks with iOS (BGTaskScheduler). Must be called synchronously in application(_:didFinishLaunchingWithOptions:) - it cannot be deferred.
  • Throws: AlphynSDKError.backgroundTaskRegistrationFailed if registration fails.

initialize(interval:debugHash:vmScannerConfig:)

  • Signature: static func initialize(interval: TimeInterval = 45, debugHash: String? = nil, vmScannerConfig: VMScannerConfig = VMScannerConfig()) async throws
  • Description: Initializes the Alphyn SDK. This method is async - call it with try await (e.g. inside a Task).
  • Parameters:
    • interval: The interval in seconds for background security scans. Must be greater than 8 seconds (default is 45 seconds).
    • debugHash: Development-only hash from the Alphyn Portal. Never ship it in production builds.
    • vmScannerConfig: Runtime hints for the VM scanner (appUsesJSContext, appUsesMonoRuntime - set appUsesMonoRuntime: true for Unity Mono hosts).
  • Throws: AlphynSDKError.invalidInterval if the interval is invalid. Calling it again after a successful initialization emits an initFailed event and returns.

initializeSync(interval:debugHash:) / registerSync()

  • Description: Synchronous wrappers for hosts that cannot use Swift concurrency (Obj-C selectors: initializeSyncWithInterval:debugHash:error:, registerSyncAndReturnError:).

setInterval(_ interval: TimeInterval)

  • Signature: static func setInterval(_ interval: TimeInterval) throws
  • Description: Updates the scan interval in seconds after initialization. Must be greater than 8.
  • Throws: AlphynSDKError.notInitialized, AlphynSDKError.invalidInterval.

isInitialized()

  • Returns: Bool - true if initialized, false otherwise.
  • Thread: Thread-safe

addSecurityListener(_ listener: AlphynSecurityListener) / removeSecurityListener(_ listener: AlphynSecurityListener)

  • Description: Adds/removes a security event listener (held weakly; callbacks are delivered on the main thread).
  • Thread: Thread-safe

All getters are throws and fail with AlphynSDKError.notInitialized before initialization.

MethodReturnsDescription
getScanResult()StringLatest scan summary (empty string if no scan yet)
getAllScanResults(startDate: Date? = nil, endDate: Date? = nil)[String]Historical scan results (JSON strings), optionally date-filtered
getAppHash()StringThe app’s integrity hash
getDeviceId()StringPersistent unique device identifier
getLastScanDate()StringISO 8601 timestamp of the last scan (empty if never)
getAllRiskFactors()[String]All detected risk factors (["DEVICE_CLEAN"] when clean)
getRejectReasons()StringDetected rejection reasons
getModules()[String]Active security modules

loadProtectedAsset(atRelativePath:) / loadAsset(atRelativePath:)

  • Signature: static func loadProtectedAsset(atRelativePath relativePath: String) throws -> Data
  • Description: Loads an Alphyn-encrypted asset bundled with your app and returns the decrypted bytes. Swift-only overloads with named:withExtension:subdirectory: are also available.

High-risk actions are verified with signAction, which signs the transaction with a hardware-backed key belonging to an enrolled user and returns a short-lived token your backend validates server-side. See MFA Transaction Signing for the three-call flow, and MFA on iOS for the signatures.

AlphynSDKError cases: notInitialized, invalidInterval(message:value:), paymentRequired(message:), backgroundTaskRegistrationFailed(message:), generic(message:), unknown.