/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
Version 4

Mark push notifications as delivered

Copy link

You can now track whether push notifications has been successfully delivered to all the intended devices by the Sendbird server. Using the SendbirdChat.markPushNotificationAsDelivered(remoteNotificationPayload:) method implemented in Notification Service Extension, you can mark a push notification as delivered to a device.

To ensure proper functionality, the SendbirdChat.setAppGroup() method must be called both in the AppDelegate.application(_ application:, didFinishLaunchingWithOptions:) method and NotificationService.didReceive(_ request:, withContentHandler:) method.

In order to check the delivery rate of push notifications, the SDK retrieves the tracking ID for push notifications and is sent to the server to identify which push notification has been successfully delivered to the device.

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            // Modify the notification content here
            bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"

            SendbirdChat.setAppGroup("APP_GROUP")
            SendbirdChat.markPushNotificationAsDelivered(remoteNotificationPayload: bestAttemptContent.userInfo) { (error) in
                guard error == nil else {
                    // Handle error.
                    return
                }
            }
            contentHandler(bestAttemptContent)
        }
    }
}

In AppDelegate.swift, set the created app group with the setAppGroup: method. To ensure the delivery delivery of push notifications, SendbirdChat.setAppGroup() must be called on your app's AppDelegate and Notification Service Extension as shown in the code below. You can see how to configure the App Group in the delivery-receipt page.

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        SendbirdChat.initialize(params: InitParams(applicationId: "APP_ID"))
        SendbirdChat.setAppGroup("APP_GROUP")

        return true
    }
}