Swift Package Manager Integration
Requirements
Installing the iOS SDK via Swift Package Manager 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 and Push Stories support is not yet available via Swift Package Manager.
Push Stories are available through a side-by-side integration with Cocoapods.
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.
Enter the url of our iOS SDK repository (https://github.com/Appboy/appboy-ios-sdk
) in the text field and click Next:
On the next screen, select the SDK version and click Next.
Versions 3.29.0 and higher are compatible with Swift Package Manager.
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.).
Make sure you select either
AppboyKit
orAppboyUI
. Including both packages can lead to undesired behavior.
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.
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:
1 2
rm -rf "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Frameworks/libAppboyKitLibrary.a" rm -rf "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Plugins/libAppboyKitLibrary.a"
Step 3: Updating your App Delegate
Add the following line of code to your AppDelegate.m
file:
1
#import "AppboyKit.h"
Within your AppDelegate.m
file, add the following snippet within your application:didFinishLaunchingWithOptions
method:
1
2
3
[Appboy startWithApiKey:@"YOUR-APP-IDENTIFIER-API-KEY"
inApplication:application
withLaunchOptions:launchOptions];
Add the following line of code to your AppDelegate.swift
file:
1
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
:
1
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.
Be sure to update YOUR-APP-IDENTIFIER-API-KEY
with the correct value from your App Settings page. For more information on where to find your App Identifier API key, check out our API documentation.
Be sure to initialize Braze in your application’s main thread. Initializing asynchronously can lead to broken functionality.
Step 4: Specify Your Data Cluster
Note that as of December 2019, custom endpoints are no longer given out, if you have a pre-existing custom endpoint, you may continue to use it. For a list of our available endpoints, click here.
Compile-time Endpoint Configuration (Recommended)
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 Appboy dictionary to yourInfo.plist
file. Inside theAppboy
dictionary, add theEndpoint
string subentry and set the value to your custom endpoint URL’s authority (for example,sdk.iad-01.braze.com
, nothttps://sdk.iad-01.braze.com
).
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 theappboyOptions
parameter passed tostartWithApiKey:inApplication:withLaunchOptions:withAppboyOptions:
. Set the value to your custom endpoint URL’s authority (for example,sdk.iad-01.braze.com
, nothttps://sdk.iad-01.braze.com
).
To find out your specific cluster, please ask your Customer Success Manager or reach out to our support team.
Implementation Example
See the AppDelegate.m
file in the Stopwatch sample app.