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

Mark messages as delivered

Copy link

Delivery receipt can be used to see whether a message has been successfully delivered to all intended recipients by the Sendbird server. To mark messages as delivered when a group channel member successfully receives a push notification for the message from APNs, the markAsDelivered(remoteNotificationPayload:completionHandler:) method should be implemented in Notification Service Extension.

import SendbirdChatSDK

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.markAsDelivered(remoteNotificationPayload: bestAttemptContent.userInfo) { error in
                guard error == nil else {
                    // Handle error.
                    return
                }
            }

            contentHandler(bestAttemptContent)
        }
    }

}

Receive an update event for delivery receipts

Copy link

When a message is delivered to a group channel member who is online, it is automatically marked as delivered and other members who are online are also notified of the delivery receipt through the channelDidUpdateDeliveryStatus(_:) method of GroupChannelDelegate.

However, when a message is delivered to an offline member as a push notification, the message can be marked as delivered through the markAsDelivered(remoteNotificationPayload:completionHandler:) method of SendbirdChat, and other members who are online are notified of the successful message delivery through the channelDidUpdateDeliveryStatus(_:) method.

class GroupChannelChattingViewController: UIViewController, GroupChannelDelegate {
    func initViewController() {
        SendbirdChat.add(self as GroupChannelDelegate, identifier: UNIQUE_DELEGATE_ID)
    }

    func channelDidUpdateDeliveryStatus(_ channel: GroupChannel) {

    }
}