Skip to content

iOS Setup


Installation

Ansa is available via Swift Package Manager.

  1. Follow the instructions for adding package dependencies to your app in Xcode.
  2. In the "Enter Package URL" field, enter this GitHub repository:
    https://github.com/getansa/ansa-core-ios
    
  3. Select the version of the SDK for iOS that you want to use. For new projects, we recommend specifying the latest version and using the "Exact Version" option.
  4. Import AnsaCore

Initialization

Initialization of the SDK requires your merchant publishable key from onboarding as well as setting up a ClientSecretProvider implementation.

/// Interface to provide Ansa with a short-lived token for access customer specific endpoints.
public protocol ClientSecretProvider {
    /// Provider for a short lived token for accessing customer specific endpoints.
    /// * Parameters:
    ///    * ansaCustomerId: unique identifier for a given customer
    ///
    /// * Returns: a short lived token for this customer
  func provideClientSecret(ansaCustomerId: String) async -> String?
}

To initialize the SDK, call:

AnsaSdk.initialize(
      publishableKey: "your publishable key",
      clientSecretProvider: ClientSecretProviderImpl()
)

Logging

Ansa supports allowing you to hook up any logging internally in AnsaClient to your preferred logging framework (swift-log, SwiftyBeaver, etc.) via a logging plugin during init().

AnsaSdk.initialize(
      logging: Logging(level: LogLevel.error, log: { message in logger.error(message)}),
      publishableKey: "your publishable key",
      clientSecretProvider: ClientSecretProviderImpl()
    )