AppIntegrityModuleApi
class AppIntegrityModuleApi
Entry point to the app integrity features of Unblu: app update checks, device security checks, App Attest based device integrity verification, screen capture protection and device binding.
Access it through the shared AppIntegrityModuleApi.instance.
-
Returns a
DeviceBindingApithat talks to the Unblu server over REST. Call once and reuse.Pass the same
UnbluClientConfigurationyou will later hand toUnbluClient. Building the configuration does not initialize the SDK, so this can run first. The binding reads everything it needs from it —unbluBaseUrl,entryPath,preferencesStorage(so it reuses / persists the shared device id),customCookies(always sent), andauthenticationChallengeDelegate(+ the PKCS#12 the host configured) for mutual TLS (mTLS) — which keeps it consistent with the initialized SDK.Declaration
Swift
func getDeviceBindingApi(clientConfiguration: UnbluClientConfiguration, username: String, password: String, restPath: String = "/rest/v4") -> DeviceBindingApiParameters
clientConfigurationThe configuration you will reuse for
UnbluClient. Single source of truth for server URL, entry path, preferences storage, custom cookies and TLS handling.usernameUsername for the dedicated device-binding REST login.
passwordPassword for
username.restPathREST API prefix. Defaults to
/rest/v4. -
The
UserDefaultskey under which the App Attest key ID is stored.Declaration
Swift
static let keyIdKey: String -
The shared instance.
Declaration
Swift
static let instance: AppIntegrityModuleApi -
Checks the App Store for an available update and compares it with the current app version.
Workflow:
- Retrieves the current app version and bundle identifier from the app’s info dictionary.
- Constructs the App Store lookup URL using the bundle identifier.
- Makes a network request to fetch the app details from the App Store.
- Parses the response to extract the latest available version and compare it with the current version.
- Invokes the completion handler with the update status and relevant App Store details.
Declaration
Swift
func checkForAppUpdate(completion: @escaping (Bool, String?, String?) -> Void)Parameters
completionA closure invoked upon completion of the update check.
-
Opens the App Store page for the application to prompt the user to update.
Workflow:
- Constructs the App Store URL using the provided app ID.
- Attempts to open the URL in the App Store app.
- Invokes the completion handler with the success status of opening the App Store.
Declaration
Swift
func enforceAppUpdate(appID: String, completion: @escaping (Bool) -> Void)Parameters
appIDThe unique identifier of the app in the App Store.
completionA closure invoked with a
Boolindicating whether the App Store opened successfully. -
Checks the security policies of the device, including passcode and biometric authentication.
- Determines if a passcode or biometric authentication is enabled on the device.
Identifies the type of biometric authentication available (Face ID, Touch ID, or none).
Declaration
Swift
func checkDeviceSecurityPolicy() -> (isPasscodeEnabled: Bool, isBiometricEnabled: Bool, biometricType: LABiometryType?)Return Value
A tuple containing:
isPasscodeEnabled(Bool):trueif either passcode or biometric authentication is enabled.isBiometricEnabled(Bool):trueif biometric authentication (Face ID or Touch ID) is enabled.biometricType(LABiometryType?): The type of biometric authentication available on the device (faceID,touchID, ornone).
-
Checks whether the app is running in an emulator (simulator) or under a debugger.
- Detects if the app is being traced (debugged).
Detects if the app is running in an emulator.
Declaration
Swift
func isRunningInEmulatorOrDebugger() -> BoolReturn Value
trueif the app is running in an emulator or is being debugged, otherwisefalse. -
Enables background mode overlay to obscure the app’s content when sent to the background.
Declaration
Swift
func enableBackgroundModeOverlay() -
- Disables the background mode overlay and removes observers to prevent memory leaks.
Declaration
Swift
func disableBackgroundModeOverlay() -
Asks Apple to attest to the validity of a generated cryptographic key.
- challenge: A
Dataobject containing a nonce. - completion: A closure invoked upon completion of the assertion generation.
- The first
Data?is a statement from Apple about the validity of the key associated with keyId. - The second
Data?is the key ID as Data.
Declaration
Swift
func attestKey(challenge: String, completion: @escaping (Data?, Data?) -> Void)Parameters
challengeA
Dataobject containing a nonce.completionA closure invoked upon completion of the assertion generation.
- challenge: A
-
Generates an assertion to verify the legitimacy of an instance of your app running on a device.
This function should be called:
- After
attestKeyto obtain thekeyId. After
UnbluClient.getChallengeto obtain the nonce.
The result should be passed to
UnbluClient.verifyAssertionfor further validation.Declaration
Swift
func generateAssertion(keyId: String, challenge: Data?, completion: @escaping (Data?) -> Void)Parameters
keyIdA unique identifier for the attestation key that was created or provided during app attestation.
challengeA
Dataobject containing a nonce used to generate the assertion.completionA closure invoked upon completion of the assertion generation.
- After
-
Generates a token that identifies the current device.
The app you use to generate the token must be linked to your developer account. Otherwise, the token generation request will fail.
The result should be passed to
UnbluClient.verifyDeviceTokenfor further validation.Declaration
Swift
func generateDeviceToken(completion: @escaping (String?) -> Void)Parameters
completionA string containing a base64-encoded ephemeral token that uniquely identifies the current device.
-
Verify the device token generated by
generateDeviceTokenusing the provided agent client.Declaration
Swift
func verifyDeviceToken(unbluAgent: any UnbluAgentClient, token: String, completion: @escaping (Bool) -> Void)Parameters
unbluAgentThe agent client used to call backend verification endpoints.
tokenThe device token to verify.
completionA closure that is called with
trueif the token is valid. -
Retrieves a cryptographic nonce (challenge) using the provided agent client.
Declaration
Swift
func getChallenge(unbluAgent: any UnbluAgentClient, completion: @escaping (String) -> Void)Parameters
unbluAgentThe agent client used to request the nonce.
completionA closure that is called with the nonce challenge
String. -
Verifies an attestation object using the provided challenge and key identifier.
Declaration
Swift
func verifyAttestation(unbluAgent: any UnbluAgentClient, attestationObject: Data, challenge: Data, keyId: Data, completion: @escaping (Bool) -> Void)Parameters
unbluAgentThe agent client used to call backend verification endpoints.
attestationObjectThe attestation
Datato verify.challengeThe original challenge
Dataused during attestation.keyIdThe key identifier
Dataassociated with the attestation.completionA closure that is called with
trueif the attestation is valid. -
Verifies an assertion object using the provided challenge and key identifier.
Declaration
Swift
func verifyAssertion(unbluAgent: any UnbluAgentClient, assertionObject: Data, challenge: Data, keyId: Data, completion: @escaping (Bool) -> Void)Parameters
unbluAgentThe agent client used to call backend verification endpoints.
assertionObjectThe assertion
Datato verify.challengeThe original challenge
Dataused during assertion.keyIdThe key identifier
Dataassociated with the assertion.completionA closure that is called with
trueif the assertion is valid. -
Callbacks required for verifying device integrity with your backend.
See moreDeclaration
Swift
struct DeviceIntegrityVerifier -
Shared verifier used by
handleDeviceIntegrityChecks(timeout:).Declaration
Swift
static var integrityVerifier: AppIntegrityModuleApi.DeviceIntegrityVerifier? -
Runs the device integrity flow using the shared verifier and blocks until it completes or times out.
Declaration
Swift
static func handleDeviceIntegrityChecks(timeout: TimeInterval = 20) -> Bool -
Runs the device integrity flow with the verifier provided and blocks until it completes or times out.
Declaration
Swift
static func handleDeviceIntegrityChecks(verifier: AppIntegrityModuleApi.DeviceIntegrityVerifier, timeout: TimeInterval = 20) -> Bool -
Runs the device integrity flow asynchronously and calls completion with the result.
Example:
let unbluAgent = Unblu.createAgentClient(withConfiguration: condig) let api = AppIntegrityModuleApi.instance let verifier = AppIntegrityModuleApi.DeviceIntegrityVerifier( verifyDeviceToken: { token, completion in api.verifyDeviceToken(unbluAgent: unbluAgent, token: token, completion: completion) }, getChallenge: { completion in api.getChallenge(unbluAgent: unbluAgent, completion: completion) }, verifyAttestation: { attestation, challenge, keyId, completion in api.verifyAttestation( unbluAgent: unbluAgent, attestationObject: attestation, challenge: challenge, keyId: keyId, completion: completion ) }, verifyAssertion: { assertion, challenge, keyId, completion in api.verifyAssertion( unbluAgent: unbluAgent, assertionObject: assertion, challenge: challenge, keyId: keyId, completion: completion ) } ) AppIntegrityModuleApi.handleDeviceIntegrityChecks(verifier: verifier) { isOk in }Declaration
Swift
static func handleDeviceIntegrityChecks(verifier: AppIntegrityModuleApi.DeviceIntegrityVerifier, completion: @escaping (Bool) -> Void) -
Runs the device integrity flow using an
UnbluAgentClient.Steps: 1) Generate a device token and verify it with the backend. 2) Fetch a challenge from the backend. 3) If a keyId exists, generate an assertion and verify it. 4) Otherwise, attest a new key, verify the attestation, then generate and verify the assertion.
Declaration
Swift
static func handleDeviceIntegrityChecks(unbluAgent: any UnbluAgentClient, completion: @escaping (Bool) -> Void)Parameters
unbluAgentThe agent client used to call backend verification endpoints.
completionCalled with
trueif all verification steps succeed. -
Allows checking if the device identifier needs to be generated, as it may not be present in the secure store.
Declaration
Swift
var isFirstLaunch: Bool { get } -
Retrieves the unique device identifier stored in the system. This identifier is generated and stored if it doesn’t already exist. Even if the app is reinstalled, this identifier will remain the same.
Declaration
Swift
func getDeviceIdentifier() -> String -
Generates a new RSA key pair if none exists in the Keychain.
Declaration
Swift
func generateKeyPair() -> String? -
Signs a given challenge string using the stored private key.
Declaration
Swift
func signBindingChallenge(challenge: String) -> String? -
Deletes both private and public keys from the Keychain. After deleting, you can generate a new key pair to re-bind the app.
Declaration
Swift
func resetKeyPair() -> Bool -
Returns the existing device-binding public key from the Keychain, encoded as base64 X.509 SubjectPublicKeyInfo. This is the key the device registers with the server during device binding.
The returned value matches the encoding produced by
generateKeyPair(). Returnsnilif no key pair is currently stored.Declaration
Swift
func encodedExistingPublicKey() -> String? -
Overlays a secure text field on the main window to disable screen capture and recording.
Declaration
Swift
func disableMainWindowCaptureAndRecording() -
Presents a full-screen SwiftUI QR scanner over the current key window’s topmost view controller. The scanner auto-dismisses on first decoded QR code or when the user taps Cancel.
Declaration
Swift
func scanQRCode(hint: String = "Align the QR code within the frame", cancelTitle: String = "Cancel", success: @escaping (String) -> Void, fail: @escaping (String) -> Void)Parameters
hintOverlay text shown below the aim frame. Pass a localized string; defaults to English. Pass an empty string to hide it.
cancelTitleTitle of the cancel button. Pass a localized string; defaults to English.
successCalled on the main thread with the raw QR payload string.
failCalled on the main thread with a description of why the scan didn’t yield a result (camera denied/unavailable, cancelled by user, no view controller available to present the scanner).