Initial setup for iOS SDK

Install and configure the iOS SDK

Install the SDK

Swift Package Manager is the recommended way to install the Exponea iOS SDK.

🚧

5.1.0 is the last SDK version on CocoaPods

CocoaPods trunk became read-only on December 2, 2026, so 5.1.0 is the last SDK version available on CocoaPods. Later versions, including bug fixes and security fixes, are available only through Swift Package Manager.

Versions already published to CocoaPods stay installable, so existing CocoaPods builds keep working.

To keep receiving SDK updates, migrate from CocoaPods to Swift Package Manager.

The instructions below use the menus of recent Xcode versions. The screenshots may show an older Xcode version.

Install with Swift Package Manager

  1. Open File > Add Package Dependencies...
  2. In the dialog that appears, enter the Exponea iOS SDK repository URL https://github.com/exponea/exponea-ios-sdk in the search box.
  3. In the Dependency Rule section, select Up to Next Major Version and the SDK version.
    Add Package Dependencies dialog
  4. Click on Add Package.
  5. In the next dialog, select the ExponeaSDK product and set Add to Target to your app target. If you use rich push notifications, also select ExponeaSDK-Notifications and add it to your notification extension targets. You can also add it later, as described in Notification extensions.
    Choose Packages dialog
  6. Click on Add Package.

To update the SDK later, select File > Packages > Update to Latest Package Versions, or change the version rule in your project's Package Dependencies tab.

Migrate from CocoaPods to Swift Package Manager

If your app installs the SDK with CocoaPods, follow these steps to migrate to Swift Package Manager. The steps cover the app target and the notification extension targets.

❗️

Don't install the SDK with both CocoaPods and Swift Package Manager. Two copies cause build errors or duplicate classes at runtime. Remove the SDK pods from all targets before you add the Swift package.

  1. Find your current SDK version in Podfile.lock, under ExponeaSDK. When you add the package in step 5, select this version or a newer one in the Dependency Rule section. If you move to a newer major version, also follow the SDK version update guide.
  2. In your Podfile, remove the pod "ExponeaSDK" and pod "ExponeaSDK-Notifications" lines from every target, including the notification service and content extension targets. Remove any target block that is now empty.
  3. Update your project:
    • If your Podfile contains other pods, run pod install and keep using the .xcworkspace file.
    • If the SDK was your only pod, run pod deintegrate, then delete the Podfile, Podfile.lock, the Pods folder, and the .xcworkspace file that CocoaPods created. Open the .xcodeproj file from now on.
  4. If your app uses SwiftSoup through CocoaPods, move it to Swift Package Manager too. The SDK depends on SwiftSoup, and it must not be installed through both dependency managers.
  5. Add the SDK package and the ExponeaSDK product to your app target, as described in Install with Swift Package Manager.
  6. For each notification extension target, open the target's settings. On the General tab, in the Frameworks, Libraries, and Embedded Content section, click + and add ExponeaSDK-Notifications. Both products come from the same package, so the app and the extensions use the same SDK version.
  7. Keep your code unchanged. The module names stay the same: import ExponeaSDK in the app and import ExponeaSDK_Notifications in the extensions.
  8. Optional: if you set User Script Sandboxing to No only for CocoaPods, set it back to Yes.
  9. Select Product > Clean Build Folder, then build and run the app. Check that push notifications work, including rich push notifications on a physical device.

Install with CocoaPods (last version: 5.1.0)

🚧

Use CocoaPods only if you can't migrate to Swift Package Manager yet. CocoaPods installs stay on 5.1.0, the last version published to CocoaPods, and don't receive any later fixes.

  1. Install CocoaPods if you haven't done so yet.

  2. Create a file named Podfile in your Xcode project folder.

  3. Add the following to your Podfile:

    platform :ios, '15.0'
    use_frameworks!
    
    target 'YourAppTarget' do
      pod "ExponeaSDK", "5.1.0"
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
        end
      end
    end

    (Replace 15.0 with your desired iOS deployment target and YourAppTarget with your app target's name)

    The post_install block sets the deployment target of the SDK's dependencies, such as SwiftSoup, to iOS 15.0. Without it, Xcode 27 and later fail to build them. If your Podfile already has a post_install block, add the loop to it, because a Podfile can have only one.

  4. In a terminal window, navigate to your Xcode project folder and run the following command:

    pod install
  5. Open the file HelloWorld.xcworkspace, located in your project folder, in Xcode.

  6. Build your app. If the build fails with a Sandbox: ... deny error in a [CP] build phase, select your project in Xcode, open the Build Settings tab, and under Build Options change User Script Sandboxing from Yes to No.

pod "ExponeaSDK", "5.1.0" installs 5.1.0, the last version available on CocoaPods. For more information, refer to Specifying pod versions in the CocoaPods documentation.

On CocoaPods, the SDK's SwiftSoup dependency is limited to version 2.11.3, the last version published there. Swift Package Manager installs the newest compatible SwiftSoup version.

Initialize the SDK

Now that you have installed the SDK in your project, you must import, configure, and initialize the SDK in your application code.

❗️

Protect the privacy of your customers

Make sure you have obtained and stored tracking consent from your customer before initializing Exponea iOS SDK.

To ensure you're not tracking events without the customer's consent, you can use Exponea.shared.clearLocalCustomerData(appGroup: String) when a customer opts out from tracking (this applies to new users or returning customers who have previously opted out). This will bring the SDK to a state as if it was never initialized. This option also prevents reusing existing cookies for returning customers.

Refer to Clear local customer data for details.

If the customer denies tracking consent after Exponea iOS SDK is initialized, you can use Exponea.shared.stopIntegration() to stop SDK integration and remove all locally stored data.

Refer to Stop SDK integration for details.

The SDK supports two integration modes: Project/Marketing and Stream/Data hub. The required configuration parameters differ by mode.

Project/Marketing mode requires projectToken, authorization.token, and baseUrl. You can find these as Project token, API Token, and API Base URL in the Marketing web app under Project settings > Access management > API:

Project token, API Base URL, and API key

Stream/Data hub mode requires streamId (and optionally baseUrl). Authentication is handled via JWT tokens provided after configuration.

📘

Refer to Mobile SDKs API access management for details.

Import the SDK:

import ExponeaSDK

Initialize the SDK with Project/Marketing settings:

Exponea.shared.configure(
    Exponea.ProjectSettings(
        projectToken: "YOUR PROJECT TOKEN",
        authorization: .token("YOUR API KEY"),
        baseUrl: "https://api.exponea.com"
    ),
    pushNotificationTracking: .disabled
)

Or initialize the SDK with Stream/Data hub settings:

Exponea.shared.configure(
    Exponea.StreamSettings(
        streamId: "YOUR_STREAM_ID",
        baseUrl: "https://api.exponea.com"
    ),
    pushNotificationTracking: .enabled(appGroup: "YOUR_APP_GROUP")
)

> 📘 Note
>
> Refer to USER.DH documentation for more details on how you can [configure iOS SDK with JWT authentication](https://documentation.bloomreach.com/data-hub/docs/configure-android-sdk-with-jwt-authentication)

// After configuration, register JWT error handler and provide initial token:
Exponea.shared.setJwtErrorHandler { context in
    yourBackend.fetchNewJwt { newToken in
        Exponea.shared.setSdkAuthToken(newToken)
    }
}
Exponea.shared.setSdkAuthToken("YOUR_STREAM_JWT_TOKEN")

For Stream mode, see Stream JWT authorization for details on JWT lifecycle management.

Your AppDelegate's application:didFinishLaunchingWithOptions method is typically a good place to do the initialization but, depending on your application design, it can be anywhere in your code.

📘

If your app uses the UIScene lifecycle (UIApplicationSceneManifest), also subclass ExponeaSceneDelegate in your SceneDelegate to track universal links. Push notifications still rely on ExponeaAppDelegate / UIApplicationDelegate and need no scene delegate changes. Learn more about universal links for the iOS SDK.

At this point, the SDK is active and should now be tracking customers and events in your app.

Configure application ID

Multiple mobile apps: If your Marketing project supports multiple mobile apps, specify the applicationID in your configuration. This helps distinguish between different apps in your project.

Exponea.shared.configure(
    Exponea.ProjectSettings(
        projectToken: "YOUR PROJECT TOKEN",
        authorization: .token("YOUR API KEY"),
        baseUrl: "https://api.exponea.com",
        applicationID: "<Your application id>" 
    ),
    pushNotificationTracking: .disabled
)

Make sure your applicationID value matches exactly Application ID configured in your Marketing under Project Settings > Campaigns > Channels > Push Notifications.

Single mobile app: If your Marketing project supports only one app, you can skip the applicationID configuration. The SDK will automatically use the default value default-application.

SDK initialization immediately creates a new customer profile with a new cookie soft ID unless the customer has been identified previously.

📘

Refer to Tracking for iOS SDK for details on which events are automatically tracked by the SDK.

❗️

Configuring the SDK using a plist file is deprecated but still supported for backward compatibility.

Other SDK configuration

Advanced configuration

The SDK can be further configured by providing additional parameters to the configure method. For a complete list of available configuration parameters, refer to the Configuration for iOS SDK documentation.

Log level

The SDK supports the following log levels:

Log levelDescription
.noneDisables all logging
.errorSerious errors or breaking issues
.warningWarnings and recommendations + .error
.verboseInformation about all SDK actions + .warning + .error.

The default log level is .warn. While developing or debugging, setting the log level to .verbose can be helpful.

You can set the log level at runtime as follows:

Exponea.logger.logLevel = .verbose
👍

For better visibility, log messages from the SDK are prefixed with [EXP-iOS].

Authorization

Read Authorization for iOS SDK to learn more about the different authorization modes supported by the SDK and how to use customer token authorization.

Data flushing

Read Data flushing for iOS SDK to learn more about how the SDK uploads data to the Marketing API and how to customize this behavior.


Did this page help you?

© Bloomreach, Inc. All rights reserved.