User & Inbox Authorization
Pulsate does not use auth tokens or a separate inbox login. Identity is established with an alias (see Session management via startPulsateSession(forAlias:)), and authorization is a simple boolean gate: you tell the SDK whether the current user is allowed to see gated content. While a user is unauthorized, Pulsate blocks messages and cards that would otherwise open — for example, a user tapping a notification cannot enter the feed until you authorize them.
By default every user is authorized. Flip the flag to false when a user signs out (or before they complete your login flow) and back to true once they authenticate.
1. Setting the authorization flag
Section titled “1. Setting the authorization flag”Use setUserAuthorized(_:) to tell the SDK whether the current user may see gated content, and isUserAuthorized() to read the current value.
import PULPulsate
let manager = PULPulsateFactory.getDefaultInstance()
// User failed / has not completed your login flowmanager?.setUserAuthorized(false)
// User successfully authenticatedmanager?.setUserAuthorized(true)
let authorized = manager?.isUserAuthorized() ?? false2. Login / logout convenience methods
Section titled “2. Login / logout convenience methods”userHasLoggedIn() and userHasLoggedOut() bundle the common transitions so you don’t have to toggle several settings by hand.
userHasLoggedIn()— authorizes the user and shows any in-app / unauthorized content that was queued while they were signed out.userHasLoggedOut()— de-authorizes the user and disables in-app notifications.
let manager = PULPulsateFactory.getDefaultInstance()
// Call after your app confirms a successful sign-inmanager?.userHasLoggedIn()
// Call when the user signs outmanager?.userHasLoggedOut()3. Reacting to unauthorized actions
Section titled “3. Reacting to unauthorized actions”When an unauthorized user performs an action that would open gated content, Pulsate reports it through PULPulsateUnauthorizedManagerDelegate so you can start your own sign-in flow.
Unauthorized user actions include:
- Entering the app by tapping a card notification.
- Entering the app by tapping a message notification.
Adopt the protocol and assign the delegate:
import UIKitimport PULPulsate
@mainclass AppDelegate: UIResponder, UIApplicationDelegate, PULPulsateUnauthorizedManagerDelegate { var window: UIWindow?
func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { do { let authData = try PULAuthorizationData(withAppId: "APP_ID", andAppKey: "APP_KEY") let manager = try PULPulsateFactory.getInstance( withAuthorizationData: authData, withLaunchOptions: launchOptions ) manager.unauthorizedDelegate = self } catch { print("Pulsate init failed: \(error)") } return true }
// Called whenever an unauthorized user triggers a gated action func unauthorizedAction(_ action: String) { // Present your login / PIN flow, then call setUserAuthorized(true) }}4. Replaying the last blocked message
Section titled “4. Replaying the last blocked message”After you authorize a user, showLastUnauthorizedMessage() re-opens the card or message that was blocked while they were unauthorized. Use removeUnauthorizedMessage() instead if you want to discard the pending item rather than show it.
let manager = PULPulsateFactory.getDefaultInstance()manager?.setUserAuthorized(true)
// Redirect the user to the card/message that was blockedmanager?.showLastUnauthorizedMessage()
// …or discard it// manager?.removeUnauthorizedMessage()5. Enabling / disabling in-app notifications
Section titled “5. Enabling / disabling in-app notifications”In-app notifications are a separate control from the authorization flag. Use enable(inAppNotification:) to turn them on or off — for example, to hide in-app content from signed-out users.
let manager = PULPulsateFactory.getDefaultInstance()
manager?.enable(inAppNotification: false) // hide in-app notificationsmanager?.enable(inAppNotification: true) // show in-app notifications
let enabled = manager?.isInAppNotificationEnabled() ?? false6. Showing a blocked in-app notification
Section titled “6. Showing a blocked in-app notification”When in-app notifications are disabled, the most recent one is held by the SDK. Once you re-enable them, showLastInAppNotification(_:) displays the last blocked in-app notification.
let manager = PULPulsateFactory.getDefaultInstance()manager?.enable(inAppNotification: true)manager?.showLastInAppNotification() // or pass true to force display
