Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
/
Message
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Mark messages as delivered

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. However, when the message is delivered as a push notification to a member who is offline, the message can be marked as delivered through SendbirdChat's markAsDelivered(remoteNotificationPayload:completionHandler:) method.

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

    func channelDidUpdateDeliveryStatus(_ channel: GroupChannel) {

    }
}