Skip to main content

Push Notifications (iOS)

OpenCDP supports push device registration, delivery metrics via Notification Service Extension, and rich big-picture images via image_url.

Registering Device Token​

To send push notifications, you must register the user's APNs device token.

import UIKit
import OpenCDP

class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
OpenCDP.shared.registerDeviceToken(token)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register: \(error)")
}
}

Rich push (big-picture) via Notification Service Extension​

When the push payload includes data.image_url, use OpenCdpNotificationExtensionSession in your Notification Service Extension. The backend must set aps.mutable-content: 1.

Configure an App Group in OpenCDPConfig.iOSAppGroup so the extension can read SDK credentials.

import UserNotifications
import OpenCDP

class NotificationService: UNNotificationServiceExtension {
private let session = OpenCdpNotificationExtensionSession()

override func didReceive(
_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
) {
session.didReceive(
request,
appGroup: "group.com.yourapp.opencdp",
contentHandler: contentHandler
)
}

override func serviceExtensionTimeWillExpire() {
session.serviceExtensionTimeWillExpire()
}
}

The SDK helper:

  • Downloads image_url and attaches it as a UNNotificationAttachment
  • Delivers enriched content before posting the delivery metric (display is not blocked)
  • Attaches the image even when delivery metric prerequisites are missing

Parse the image URL in the main app with OpenCDPPushPayload.parseImageUrl(data).

For layout behavior, troubleshooting, and QA checklist, see Rich push images (mobile hub).

Handling Notifications​

Track foreground delivery and notification opens with the SDK helpers:

// Foreground delivery
OpenCDP.shared.handleForegroundPushDelivery(data)

// User tapped notification
OpenCDP.shared.handlePushNotificationOpen(data)