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.push throws ConnectError.pushNotEnabled if push was not configured at enable() time. Always pass a ConnectPushConfig (.automatic, .manual, or one with an App Group identifier) when calling enable().


Getting the push interface

let push = try ConnectSDK.shared.push

Push configuration

Configure push at SDK initialization by passing a ConnectPushConfig to enable(with:). Two modes are available:

ModeWho registers for APNs?Who forwards the device token?Use when
.automaticSDKSDKYou want the Connect SDK to manage APNs registration end-to-end.
.manualYour appYour 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
}

Automatic mode

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")
    )
)

Manual mode

Use 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(
    with: ConnectConfig(
        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)
}
📘

Note

Calling didRegisterWithToken in .automatic mode throws ConnectError.pushModeNotManual. This method is only valid in manual mode.


Status

PropertyTypeDescription
configConnectPushConfigThe push configuration used at enable(with:) time.

Authorization

Call these methods from your UNUserNotificationCenter authorization completion handler.

MethodIsolationDescription
didReceiveAuthorization(granted:error:)nonisolatedNotifies the SDK of the push permission result. Safe to call from any thread.
didReceiveAuthorization(granted:error:) async@MainActorAsync variant with ordering guarantee.
didFailToRegisterWithError(_:)nonisolatedNotifies the SDK that APNs registration failed. Safe to call from any thread.
didFailToRegisterWithError(_:) async@MainActorAsync 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.push is @MainActor-isolated. In Swift 6, accessing it from the non-isolated requestAuthorization completion handler requires a Task { @MainActor in } wrapper to satisfy strict concurrency checking.


Category registration

MethodDescription
registerNotificationCategories()Re-registers Acoustic notification categories with UNUserNotificationCenter. Call this if your app replaces the notification categories after SDK initialization.