ConnectPush
The push notification interface for the Connect iOS SDK. Access via try ConnectSDK.shared.push.
Platform: iOS 15.1+
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(). 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 automatic: ConnectPushConfig
public static let manual: ConnectPushConfig
}Automatic mode
For basic push support:
ConnectSDK.shared.enable(
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(
appKey: "YOUR_APP_KEY",
postURL: "https://collector.example.com/collectorPost",
push: ConnectPushConfig(mode: .automatic, appGroupIdentifier: "group.com.example.YourApp")
)Manual mode
Use the manual mode when your app handles APNs registration itself. You are responsible for requesting device token registration and forwarding the result to the Connect SDK.
ConnectSDK.shared.enable(
appKey: "YOUR_APP_KEY",
postURL: "https://collector.example.com/collectorPost",
push: ConnectPushConfig(mode: .manual, appGroupIdentifier: "group.com.example.YourApp")
)After APNs registration succeeds, forward the device token:
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
try? ConnectSDK.shared.push.didRegisterWithToken(deviceToken)
}
NoteCalling
didRegisterWithTokenin.automaticmode throwsConnectError.pushModeNotManual. This method is only valid in the manual mode.
Status
| Property | Type | Description |
|---|---|---|
config | ConnectPushConfig | The push configuration used at enable() time |
Authorization
Call these methods from your UNUserNotificationCenter authorization completion handler.
| 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. |
Example
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.
Category registration
| Method | Description |
|---|---|
registerNotificationCategories() | Re-registers Acoustic notification categories with UNUserNotificationCenter. Call this if your app replaces the notification categories after SDK initialization. |
Updated about 2 hours ago
