Swift Package Manager Integration


Installing the iOS SDK via Swift Package Manager (SPM) automates the majority of the installation process for you. Before beginning this process please ensure that you are using Xcode 12 or greater.

Note that tvOS is not yet available via Swift Package Manager.

Step 1: Adding the dependency to your project

Open your project and navigate to your project’s settings. Select the tab named Swift Packages and click on the add button (+) at the bottom left.

Swift Package Manager: Menu 1

When importing SDK version 3.33.1 and above, enter the url of our iOS SDK repository (https://github.com/braze-inc/braze-ios-sdk) in the text field and click Next:

For versions 3.29.0 through 3.32.0, use the URL https://github.com/Appboy/Appboy-ios-sdk.

Swift Package Manager: Menu 2

On the next screen, select the SDK version and click Next.

Versions 3.29.0 and higher are compatible with Swift Package Manager.

Swift Package Manager: Menu 3

Select the package that best fits your needs and click Finish:

  • AppboyUI
    • Best suited if you plan to use UI components provided by Braze.
    • Includes AppboyKit automatically.
  • AppboyKit
    • Best suited if you don’t need to use any of the UI components provided by Braze (e.g. Content Cards, In-App Messages, etc.).
  • AppboyPushStory
    • Include this package if you have integrated Push Stories in your app. This is supported as of version 3.31.0.
    • In the dropdown under Add to Target, select your ContentExtension target instead of your main app’s target.

Make sure you select either AppboyKit or AppboyUI. Including both packages can lead to undesired behavior.

Swift Package Manager: Menu 4

Step 2: Configuring your project

Next, navigate to your project build settings and add the -ObjC flag to the Other Linker Flags setting. Please note that this flag must be added and errors resolved in order to further integrate the SDK.

Swift Package Manager: Menu 5

Edit the scheme of the target including the Appboy package (Product > Scheme > Edit Scheme menu item):

  • Click the expand ▶︎ next to Build and select Post-actions. Press + and select New Run Script Action.
  • In the dropdown next to Provide build settings from, select your app’s target.
  • Copy this script into the open field:
    # iOS
    bash "$BUILT_PRODUCTS_DIR/Appboy_iOS_SDK_AppboyKit.bundle/Appboy.bundle/appboy-spm-cleanup.sh"
    # macOS (if applicable)
    bash "$BUILT_PRODUCTS_DIR/Appboy_iOS_SDK_AppboyKit.bundle/Contents/Resources/Appboy.bundle/appboy-spm-cleanup.sh"

Swift Package Manager: Menu 7

Step 3: Updating your App Delegate

Add the following line of code to your AppDelegate.m file:

#import "AppboyKit.h"

Within your AppDelegate.m file, add the following snippet within your application:didFinishLaunchingWithOptions method:

[Appboy startWithApiKey:@"YOUR-APP-IDENTIFIER-API-KEY"

Add the following line of code to your AppDelegate.swift file:

import AppboyKit

For more information about using Objective-C code in Swift projects, please see the Apple Developer Docs.

In AppDelegate.swift, add following snippet to your application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool:

Appboy.start(withApiKey: "YOUR-APP-IDENTIFIER-API-KEY", in:application, withLaunchOptions:launchOptions)

Note: Braze’s sharedInstance singleton will be nil before startWithApiKey: is called, as that is a prerequisite to using any Braze functionality.

Step 4: Specify Your Data Cluster

If given a pre-existing custom endpoint…

  • Starting with Braze iOS SDK v3.0.2, you can set a custom endpoint using the Info.plist file. Add the Braze dictionary to your Info.plist file. Inside the Braze dictionary, add the Endpoint string subentry and set the value to your custom endpoint URL’s authority (for example, sdk.iad-01.braze.com, not https://sdk.iad-01.braze.com). Note that prior to Braze iOS SDK v4.0.2, the dictionary key Appboy must be used in place of Braze.

Your Braze representative should have already advised you of the correct endpoint.

Runtime Endpoint Configuration

If given a pre-existing custom endpoint…

  • Starting with Braze iOS SDK v3.17.0+, you can override set your endpoint via the ABKEndpointKey inside the appboyOptions parameter passed to startWithApiKey:inApplication:withLaunchOptions:withAppboyOptions:. Set the value to your custom endpoint URL’s authority (for example, sdk.iad-01.braze.com, not https://sdk.iad-01.braze.com).
New Stuff!