Example Usage

This is an example of the most common use case of this SDK - fetching operations and approving them.

SDK Integration

Follow the SDK Integration tutorial for SDK installation.

Example Code

Note: The async/throws methods shown here also have callback-based counterparts (completion: @escaping (Result<…, WMTError>) -> Void) if you prefer the closure style.

// PowerAuth instance needs to be configured and a user-activated instance.
// More about PowerAuth SDK can be found here: https://github.com/wultra/powerauth-mobile-sdk

import PowerAuth2
import WultraMobileTokenSDK

func exampleUsage(powerAuth: PowerAuthSDK) {
    do {
        let mtoken = try powerauth.createWultraMobileToken(acceptLanguage: "de") // create the WultraMobileToken instance and set "requested content" to german language (default is english - "en")

        Task {
            do {
                let ops = try await mtoken.operations.getOperations()
                // we expect at least 1 operation in the list for the example purposes
                let auth = PowerAuthAuthentication.possessionWithPassword(password: "1234") // simulate that user entered PIN 1234
                try await mtoken.operations.authorize(operation: ops.first!, with: auth)
                // handle successful authorization
            } catch {
                // operation fetch or authorization failed
            }
        }
    } catch {
        // PowerAuth baseUrl is not valid
    }
}

For more examples see IntegrationTests

Request Interceptors

powerauth.createWultraMobileToken(...)/WultraMobileToken.init(...) also accept an optional requestInterceptors parameter - a list of WPNInterceptors applied, in order, to every outgoing request right before it’s sent. Use it for cross-cutting concerns such as a correlation ID:

class CorrelationIdInterceptor: WPNInterceptor {
    func processRequest(_ request: NSMutableURLRequest) {
        request.setValue(UUID().uuidString, forHTTPHeaderField: "X-Correlation-ID")
    }
}

let mtoken = try powerauth.createWultraMobileToken(requestInterceptors: [CorrelationIdInterceptor()])

Don’t modify the X-PowerAuth-* headers or the request body in an interceptor - doing so could lead to the backend rejecting the request.

Last updated on Sep 09, 2026 (14:14) Edit on Github Send Feedback

3.1.x

Mobile Token SDK for iOS