Delivery receipt is a feature that indicates whether a message has successfully been delivered to all the intended recipients by Sendbird server. With the implementation of delivery receipt, Sendbird not only provides the timestamp of when each user has last read the messages in each channel, but also the timestamp of when each user has the message last delivered to each user in each channel.
Note: Delivery receipt is only applicable to group channels.
Most popular messaging apps, such as WhatsApp and Facebook Messenger, provide this feature. Users who have experienced them expect to see if the message they sent has been successfully delivered when using a new chat service. Delivery receipt is a feature in high demand that today’s users are accustomed to using.
Previously, a sender had no way of knowing whether their message was unread because the server is in the process of delivering or failed to deliver the message due to the unreliable internet connection, or simply because the recipients haven’t yet read the message. This feature enables users to become better-informed, thus improving the Sendbird user experience.
Delivery receipt works in a similar way to read receipt. The server stores the timestamp of the message last delivered as delivered_ts. The timestamp is recorded per user, per channel.
Each SDK provides methods to make the Chat API's mark all messages as delivered action calls. If required, each SDK also makes necessary changes to handle the new response key, delivery_receipt, for the APIs that return a group channel resource.
To use delivery receipt, Notification Service Extension should be implemented in advance to receive the contents of your remote notifications before they are displayed to the devices of users, allowing the SDK to update the notification payload.
You can find the automatically generated files for the extension in Xcode. Choose one of the following two files and set the app group with the setAppGroup: method within the corresponding method.
To mark messages as delivered when a group channel member successfully receives a push notification for the message from APNs, the markAsDeliveredWithRemoteNotificationPayload:completionHandler: method should be implemented in Notification Service Extension.
SwiftObjective-C
import SendBirdSDK
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]"
SBDMain.setAppGroup("APP_GROUP")
SBDMain.markAsDelivered(withRemoteNotificationPayload: bestAttemptContent.userInfo) { (error) in
guard error == nil else {
// Handle error.
}
}
contentHandler(bestAttemptContent)
}
}
}
When a message is delivered to group channel members who are online, it is automatically marked as delivered and the members are notified of delivery receipt through the channelDidUpdateDeliveryReceipt: method of SBDChannelDelegate. However, when the message is delivered as a push notification to group channel members who are offline, the message can be marked as delivered through the markAsDeliveredWithRemoteNotificationPayload method of SBDMain.
SwiftObjective-C
class GroupChannelChattingViewController: UIViewController, SBDChannelDelegate {
SBDMain.add(self as SBDChannelDelegate, identifier: UNIQUE_DELEGATE_ID)
func channelDidUpdateDeliveryReceipt(_ sender: SBDGroupChannel) {
...
}
}
Retrieve number of members who haven’t received a message
You can retrieve the number of members who haven’t received a specific message in a group channel. If zero is returned, it means that the message has been delivered to all the other members.
SwiftObjective-C
let count = channel?.getUndeliveredMemberCount(message)