iOS SDK: Methods

Initialization methods

initialization

Call this method in the "Main" thread only to initialize the SDK.

To call this method, use didFinishLaunchingWithOptions in AppDelegate.

Mindbox.shared.initialization(configuration: MBConfiguration)

notificationsRequestAuthorization

Call this method to pass the notification permission status to the SDK.

Mindbox.shared.notificationsRequestAuthorization(granted: Bool)
Dispatch.main.async {
  Mindbox.shared.notificationsRequestAuthorization(granted: Bool)
}

apnsTokenUpdate

Call this method to pass the APNS token to the SDK.

Use didRegisterForRemoteNotificationsWithDeviceToken in AppDelegate.

Mindbox.shared.apnsTokenUpdate(deviceToken: deviceToken)

registerBGTasks

Call this method to register background tasks for iOS 13 and above.

Use the didFinishLaunchingWithOptions method in AppDelegate.

if #available(iOS 13.0, *) {
  Mindbox.shared.registerBGTasks()
}
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)

Retrieving data from the SDK

getDeviceUUID

Call this method to request a callback with the DeviceUUID used by the SDK.

This method returns an ID that can be used to disable the callback.

getDeviceUUID(
  _ completion: @escaping (String) -> Void
)
Mindbox.shared.getDeviceUUID{
  deviceUUID in print(deviceUUID)
}

getAPNSToken

Call this method to request a callback with the APNS token stored in the SDK.

This method returns the ID that can be used to unsubscribe from the callback.

Mindbox.shared.getAPNSToken(
  _ completion: @escaping (String) -> Void
)
val mySubscriptionid = Mindbox.subscribeFmsToken {
  deviceUUID -> Log.println(Log.INFO, "MindboxDeviceUUID", deviceUUID)
  }

Mindbox.disposeFmsTokenSubscription(mySubscriptionid)

Getting push statistics

pushDelivered

The pushDelivered method transmits push notification delivery statuses.

It can accept the entire notification response or a uniqueKey string.

It accepts the following 2 types of arguments:

  • request: <#T##UNNotificationRequest#>
  • uniqueKey: <#T##String#>
Mindbox.shared.pushDelivered()
Mindbox.shared.pushDelivered(request)

pushClicked

Call this method to transmit push notification "clicked" statuses.

The pushClicked method can accept an entire notification response or uniqueKey strings.

If the push notification body has been clicked, pushClicked fetches the uniqueKey string only. If a button is clicked, the method fetches both the uniqueKey for the click and buttonUniqueKey for the clicked button.

The method accepts any of the following 3 arguments:

  • response: <#T##UNNotificationResponse#>
  • uniqueKey: <#T##String#>
  • uniqueKey: <#T##String#>, buttonUniqueKey: <#T##String?#>
Mindbox.shared.pushClicked( )
Mindbox.shared.pushClicked(response: response)

Transmitting events

Events in Mindbox are passed using the API methods configured in your project’s administrative settings. These events can be called in two modes:

  • asynchronous — Mindbox’s API responds with a 200 status once it receives the data. Data is processed in background mode.
  • synchronous — Mindbox’s API starts processing the call once the data has been received and responds with a relevant processing status.

Passing Events Using iOS SDK

executeAsyncOperation

Run this method to execute operations in async mode.

Mindbox.shared.executeAsyncOperation(
  operationSystemName: "<operation system name>",
  operationBody:  <operation body>
)

executeSyncOperation

Run this method to execute operations in sync mode. Data will be returned through the submitted callbacks.

public func executeSyncOperation<T>(
  operationSystemName: "<operation system name>",
  operationBody: <operation body>,
  completion: @escaping (Result<OperationResponse, MindboxError>) -> Void
) where T: OperationBodyRequestType {}
public func executeSyncOperation<T, P>(
  operationSystemName: "<operation system name>",
  operationBody: <operation body>,
  customResponseType: P.Type,
  completion: @escaping (Result<P, MindboxError>) -> Void
) where T: OperationBodyRequestType, P: OperationResponseType {}

Managing logs

By default, logging is disabled for production apps.

To manage logging during development, you can add one of the following to your logger parameter:

  • debug — 🪲
  • info — ℹ️
  • default — 💡
  • error — ‼️
  • fault — ⚠️
  • none
Mindbox.logger.logLevel = .error

Mindbox.logger.log()

Call this function to display data using Mindbox’s logger. You can also call it to log any Mindbox-related data.

Mindbox.logger.log(level: <#T##LogLevel#>, message: <#T##String#>)
Mindbox.logger.log(level: .debug, message: "My message")