2. Initializing the SDK

🚧

Before you begin, make sure you have completed these steps:

👍

This guide will help you to:

  • Ensure the app starts without errors;
  • Display the DeviceUUID for Mindbox SDK in Xcode,
  • Create a Mindbox customer profile (if you create an anonymous user and add their subscriptions as part of your integration).

1. Setting up App Groups

  1. Open your project’s settings.
  2. In Targets, select your main target.
  3. Go to the Signing & Capabilities tab.
  4. Click Add and select App Groups.
  5. Add a new group with the following name template: group.cloud.Mindbox.{Bundle ID of the app}.

For example, with a Mindbox-Sample-App as the Bundle ID, the App Group should be group.cloud.Mindbox.Mindbox-Sample-App.

❗️

Make sure you create your App Group with the following template: group.cloud.Mindbox.{bundle ID of your app}

If there is an error in the main target’s app group template, the app won’t be compiled.

Consider checking the actual name using the .entitlements file.

The SDK checks if the Group name matches the template, and will display an error message if there is a mismatch.

2. Selecting an SDK configuration

Follow your marketing requirements to select a fitting SDK configuration.

🚧

Please note:

You’ll need to get a "<project endpoint>" from your Mindbox Customer Success Manager or look it up in integration point settings.

📘

Mindbox Domain API

API queries have to be submitted to the following domain: api.mindbox.cloud.

Don’t submit your Project address here!

1. To submit anonymous users to Mindbox and send them push notifications:

let mindboxSdkConfig = try MBConfiguration(
    endpoint: "<project endpoint>",
    domain: "api.mindbox.cloud",
    subscribeCustomerIfCreated: true,
    shouldCreateCustomer: true
)

2. To submit anonymous users to Mindbox without sending them push notifications:

let mindboxSdkConfig = try MBConfiguration(
endpoint: "<project endpoint>",
domain: "api.mindbox.cloud",
subscribeCustomerIfCreated: false,
shouldCreateCustomer: true
)

3. If you would not like to submit anonymous users to Mindbox:

let mindboxSdkConfig = try MBConfiguration(
endpoint: "<project endpoint>",
domain: "api.mindbox.cloud",
shouldCreateCustomer: false
)

3. SDK Initialization

Initialize the library in the didFinishLaunchingWithOptions method and use the configuration selected in the previous step.

❗️

The initialization must be carried out in the AppDelegate.swift file in sync with the main thread.

If you use SwiftUI and do not have the AppDelegate file, you will need to create it.

//
//  AppDelegate.swift
//  Sample
//
//  Created by Peter Nikitin on 06.04.2022.
//

import Foundation
import Mindbox
import UIKit

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
                ...

        do {
                    
                        SPECIFY THE SDK CONFIGURATION SELECTED AT STEP 2                    
            
            Mindbox.shared.initialization(configuration: mindboxSdkConfig)
           
        } catch  {
           print(error)
        }
       
                ...

      return true
  }
}

❗️

To check that the SDK has been initialized correctly, add the deviceUUID anywhere in the console.

Consider adding the deviceUUID output immediately after you call Mindbox.shared.initialization.

Launch the app from Xcode on an actual device or on a device simulator:

//display deviceUUID in the console
class AppDelegate: UIResponder, UIApplicationDelegate {
    override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) → Bool {
        
                ...

        Mindbox.shared.getDeviceUUID{
            deviceUUID in print(deviceUUID)
        }
                ...

      return true
  }
}

👍

You should now have the following results:

  • The app starts without errors;
  • Mindbox’s SDK displays DeviceUUID in XCode;
  • You have created a Mindbox customer profile (if you created an anonymous user and added their subscriptions as part of your integration).