Skip to content


Completing the integration

Before following these steps, make sure you have integrated the SDK using either Carthage, CocoaPods, Swift Package Manager, or a manual integration.

Step 1: Update your app delegate

If you are integrating the Braze SDK with CocoaPods, Carthage, or with a dynamic manual integration, add the following line of code to your AppDelegate.m file:

1
#import "Appboy-iOS-SDK/AppboyKit.h"

If you are integrating with Swift Package Manager or with a static manual integration, use this line instead:

1
#import "AppboyKit.h"

Next, 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];

Update YOUR-APP-IDENTIFIER-API-KEY with the correct value from your Manage Settings page. Check out our API documentation for more information on where to find your app identifier API key.

If you are integrating the Braze SDK with CocoaPods, Carthage, or with a dynamic manual integration, add the following line of code to your AppDelegate.swift file:

1
import Appboy_iOS_SDK

If you are integrating with Swift Package Manager or with a static manual integration, use this line instead:

1
import AppboyKit

Refer to the Apple developer docs for more information on using Objective-C code in Swift projects.

Next, 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)

Update YOUR-APP-IDENTIFIER-API-KEY with the correct value from your Manage Settings page. Check out our API documentation for more information on where to find your app identifier API key.

Step 2: 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 before 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).

SDK integration complete

Braze should now be collecting data from your application, and your basic integration should be complete. See the following articles to enable custom event tracking, push messaging, and the complete suite of Braze features.

Customizing Braze on startup

If you wish to customize Braze on startup, you can instead use the Braze initialization method startWithApiKey:inApplication:withLaunchOptions:withAppboyOptions: and pass in an optional NSDictionary of Braze startup keys.

In your AppDelegate.m file, within your application:didFinishLaunchingWithOptions: method, add the following Braze method:

1
2
3
4
[Appboy startWithApiKey:@"YOUR-APP-IDENTIFER-API-KEY"
          inApplication:application
      withLaunchOptions:launchOptions
      withAppboyOptions:appboyOptions];

Note that this method would replace the startWithApiKey:inApplication:withLaunchOptions: initialization method.

In AppDelegate.swift, within your application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool method, add the following Braze method where appboyOptions is a Dictionary of startup configuration values:

1
2
3
4
Appboy.start(withApiKey: "YOUR-APP-IDENTIFIER-API-KEY",
                 in:application,
                 withLaunchOptions:launchOptions,
                 withAppboyOptions:appboyOptions)

Note that this method would replace the startWithApiKey:inApplication:withLaunchOptions: initialization method.

This method is called with the following parameters:

  • YOUR-APP-IDENTIFIER-API-KEY – Your app identifier API key from the Braze dashboard.
  • application – The current app.
  • launchOptions – The options NSDictionary that you get from application:didFinishLaunchingWithOptions:.
  • appboyOptions – An optional NSDictionary with startup configuration values for Braze.

See Appboy.h for a list of Braze startup keys.

Appboy.sharedInstance() and Swift nullability

Differing somewhat from common practice, the Appboy.sharedInstance() singleton is optional. This is because sharedInstance is nil before startWithApiKey: is called, and there are some non-standard but not-invalid implementations in which a delayed initialization can be used.

If you call startWithApiKey: in your didFinishLaunchingWithOptions: delegate before any access to Appboy’s sharedInstance (the standard implementation), you can use optional chaining, like Appboy.sharedInstance()?.changeUser("testUser"), to avoid cumbersome checks. This will have parity with an Objective-C implementation that assumed a non-null sharedInstance.

Additional resources

Full iOS class documentation is available to provide additional guidance on any SDK methods.

HOW HELPFUL WAS THIS PAGE?
New Stuff!