Skip to content

Running the Pulsate SDK

This page explains how to initialize and run the Pulsate SDK. Complete the installation guide first.

The SDK uses a factory to create a singleton manager instance. Initialize it in your AppDelegate’s application(_:didFinishLaunchingWithOptions:) method, and pass along the launchOptions dictionary.

import PULPulsate
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
do {
let authData = try PULAuthorizationData(
withAppId: "YOUR_SDK_APP_ID",
andAppKey: "YOUR_SDK_APP_KEY")
let pulsateManager = try PULPulsateFactory.getInstance(
withAuthorizationData: authData,
withLaunchOptions: launchOptions)
pulsateManager.startPulsateSession { success, error in
if let error = error {
print("Pulsate session failed: \(error)")
}
}
} catch {
print("Pulsate initialization failed: \(error)")
}
return true
}
}

Both PULAuthorizationData(withAppId:andAppKey:) and PULPulsateFactory.getInstance(...) are throwing initializers, so wrap them in a do { … } catch { … } block. PULAuthorizationData validates that the App ID and App Key are non-nil and 64 characters long, and throws otherwise.

As an alternative to passing keys in code, you can store your App ID and App Key under a Pulsate dictionary in your Info.plist and use the plist-based initializer:

let pulsateManager = try PULPulsateFactory.getInstance(
withLaunchOptions: launchOptions)

Controlling the app and notification delegates

Section titled “Controlling the app and notification delegates”

By default, Pulsate takes ownership of your app’s UIApplicationDelegate and UNUserNotificationCenterDelegate so it can handle push and lifecycle events for you. To keep your own delegates and forward events manually, use the full initializer:

let pulsateManager = try PULPulsateFactory.getInstance(
withAuthorizationData: authData,
withLaunchOptions: launchOptions,
withPulsateAppDelegate: false,
andPulsateNotificationDelegate: false)

If you opt out, you must forward the relevant UIApplicationDelegate and UNUserNotificationCenterDelegate callbacks to the proxy returned by pulsateManager.getPulsateSystemManager().

After the manager is created, retrieve it anywhere in your app with getDefaultInstance(). It returns nil if no instance has been created yet.

let pulsateManager = PULPulsateFactory.getDefaultInstance()

Continue to Managing Pulsate Sessions.