Example SDK Flow
This page ties the SDK together in a realistic app. The app has a login flow and enables in-app notifications only for signed-in users, while keeping Pulsate active in the background so pushes, geofences, and sessions keep working.
1. Initialize in the AppDelegate
Section titled “1. Initialize in the AppDelegate”Create the manager in application(_:didFinishLaunchingWithOptions:). The getInstance initializer throws, so wrap it in a do/catch.
import UIKitimport PULPulsate
@mainclass AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow?
func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { do { let authData = try PULAuthorizationData(withAppId: "APP_ID", andAppKey: "APP_KEY") _ = try PULPulsateFactory.getInstance( withAuthorizationData: authData, withLaunchOptions: launchOptions ) } catch { print("Pulsate init failed: \(error)") } return true }
// When the app goes to the background, stop showing in-app notifications so a // signed-out user won't see them next time the app comes forward. func applicationDidEnterBackground(_ application: UIApplication) { PULPulsateFactory.getDefaultInstance()?.enable(inAppNotification: false) }}2. Gate in-app notifications on the login screen
Section titled “2. Gate in-app notifications on the login screen”On your login screen, enable in-app notifications for users who are already signed in and navigate them onward. Do not start the Pulsate session here (see the note in step 3).
import UIKitimport PULPulsate
class LoginViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let pulsateManager = PULPulsateFactory.getDefaultInstance()
showSpinner() if loginViewModel.isUserLoggedIn() { pulsateManager?.enable(inAppNotification: true) navigateToMainScreen() } else { hideSpinner() setupLoginScreen() } }}3. Start the session on the main screen
Section titled “3. Start the session on the main screen”Start the Pulsate session from an active view controller — the main screen — not the login screen or the AppDelegate. The session start is asynchronous and, on success, tries to attach an in-app message to the current screen. If you start it on a screen that is about to be destroyed (like a login screen after a successful sign-in), the in-app message may fail to render.
import UIKitimport PULPulsate
class MainViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let pulsateManager = PULPulsateFactory.getDefaultInstance()
pulsateManager?.startPulsateSession(forAlias: alias) { success, error in pulsateManager?.showLastInAppNotification(true) } }}This starts a session for the identified user and shows any in-app notification that was waiting to render.
4. Summary
Section titled “4. Summary”With this setup:
- Pulsate stays active in the background — geofences, pushes, and session management keep working even when your app is not in the foreground.
- In-app notifications are shown only to signed-in users, because you disable them on background and re-enable them once the user reaches the main screen.
- To also stop push notifications for signed-out users, toggle
setPushNotificationEnabled(false)on logout andsetPushNotificationEnabled(true)on login.

