Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Version 4
Home
/
Chat
/
iOS
/
Message

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

}

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

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

    func channelDidUpdateDeliveryStatus(_ channel: GroupChannel) {

    }
}