AppboyKit (also known as the Objective-C SDK) is no longer supported and has been replaced by the Swift SDK. It will no longer receive new features, bug fixes, security updates, or technical support—however, messaging and analytics will continue to function as normal. To learn more, see Introducing the New Braze Swift SDK.
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.
The sharedInstance
singleton will be nil before startWithApiKey:
is called, as that is a prerequisite to using any Braze functionality.
Be sure to initialize Braze in your application’s main thread. Initializing asynchronously can lead to broken functionality.
Step 2: 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 more details, refer to our list of available endpoints.
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 theBraze
dictionary to yourInfo.plist
file. Inside theBraze
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
). Note that before Braze iOS SDK v4.0.2, the dictionary keyAppboy
must be used in place ofBraze
.
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
).
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 optionsNSDictionary
that you get fromapplication:didFinishLaunchingWithOptions:
.appboyOptions
– An optionalNSDictionary
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.