ConnectPush
The push notification interface for the Connect iOS SDK. Access via try ConnectSDK.shared.push.
Platform: iOS 15.1+
Language: Swift only (push notifications are not supported in Objective-C apps)
Isolation: @MainActor
Declared in: ConnectSDK
Note
ConnectSDK.shared.pushthrowsConnectError.pushNotEnabledif push was not configured atenable()time. Always pass aConnectPushConfig(.automatic,.manual, or one with an App Group identifier) when callingenable().
Getting the push interface
let push = try ConnectSDK.shared.pushPush configuration
Configure push at SDK initialization by passing a ConnectPushConfig to enable(with:). Two modes are available:
| Mode | Who registers for APNs? | Who forwards the device token? | Use when |
|---|---|---|---|
.automatic | SDK | SDK | You want the Connect SDK to manage APNs registration end-to-end. |
.manual | Your app | Your app (via didRegisterWithToken) | You already manage APNs registration or need custom token handling. |
public struct ConnectPushConfig: Sendable {
public let mode: Mode
public let appGroupIdentifier: String?
// Convenience constants
public static let off: ConnectPushConfig
public static let automatic: ConnectPushConfig
public static let manual: ConnectPushConfig
}The SDK manages APNs registration end-to-end. For basic push support:
ConnectSDK.shared.enable(
with: ConnectConfig(
appKey: "YOUR_APP_KEY",
postURL: "https://collector.example.com/collectorPost",
push: .automatic
)
)To enable push delivery tracking and rich media from a Notification Service Extension, provide an App Group identifier:
ConnectSDK.shared.enable(
with: ConnectConfig(
appKey: "YOUR_APP_KEY",
postURL: "https://collector.example.com/collectorPost",
push: ConnectPushConfig(mode: .automatic, appGroupIdentifier: "group.com.example.YourApp")
)
)Status
| Property | Type | Description |
|---|---|---|
config | ConnectPushConfig | The push configuration used at enable(with:) time. |
Permission request
Use requestAuthorization(options:) to prompt the user for push notification permission directly through the SDK, without calling UNUserNotificationCenter yourself.
ConnectPushAuthorizationOptions
requestAuthorization(options:) accepts a ConnectPushAuthorizationOptions value, which mirrors UNAuthorizationOptions. The commonly used options are:
| Option | Description |
|---|---|
.alert | Display notifications in the notification center and as banners. |
.badge | Update the app icon badge. |
.sound | Play a sound when a notification is delivered. |
.provisional | Send notifications without prompting the user first. Notifications are delivered quietly to the notification center — the user can then choose to keep or turn them off. |
The default is [.alert, .badge, .sound].
Request permission
let push = try ConnectSDK.shared.push
let (granted, error) = await push.requestAuthorization()
if granted {
// User granted permission
} else if let error {
// Permission denied or error
}To request a non-default set of options:
let (granted, error) = await push.requestAuthorization(options: [.alert, .sound])Check current permission state
Use getCurrentAuthorization() to query the current authorization state without prompting the user.
let status = await push.getCurrentAuthorization()
// true = granted, provisional, or ephemeral
// false = denied
// nil = not yet determinedForward the result manually
If your app manages its own UNUserNotificationCenter authorization flow, forward the result to the SDK using didReceiveAuthorization(granted:error:) instead of calling requestAuthorization(options:).
| Method | Isolation | Description |
|---|---|---|
didReceiveAuthorization(granted:error:) | nonisolated | Notifies the SDK of the push permission result. Safe to call from any thread. |
didReceiveAuthorization(granted:error:) async | @MainActor | Async variant with ordering guarantee. |
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
Task { @MainActor in
try? ConnectSDK.shared.push.didReceiveAuthorization(granted: granted, error: error)
}
}
Note
ConnectSDK.shared.pushis@MainActor-isolated. In Swift 6, accessing it from the non-isolatedrequestAuthorizationcompletion handler requires aTask { @MainActor in }wrapper to satisfy strict concurrency checking.
Token registration
| Method | Isolation | Description |
|---|---|---|
didFailToRegisterWithError(_:) | nonisolated | Notifies the SDK that APNs registration failed. Safe to call from any thread. |
didFailToRegisterWithError(_:) async | @MainActor | Async variant with ordering guarantee. |
Category registration
| Method | Description |
|---|---|
registerNotificationCategories() | Re-registers Acoustic notification categories with UNUserNotificationCenter. Call this if your app replaces the notification categories after SDK initialization. |
