Key Benefit: Enable real-time read and delivery receipt tracking with efficient resource management, ensuring accurate message status updates while optimizing performance and network usage.

Feature Overview

Message Receipt Sync provides the essential infrastructure for real-time tracking of message read and delivery status within channels. This system ensures that read counts, delivery confirmations, and user interaction data remain current and accurate across your chat application.

Real-time Synchronization

Live receipt tracking
  • Start/stop receipt sync control
  • Automatic status updates
  • Real-time event processing
  • Connection state management

Resource Optimization

Efficient system management
  • Lifecycle-aware activation
  • Automatic cleanup processes
  • Network resource conservation
  • Performance optimization
Resource Consumption: Receipt sync consumes real-time event topics and should only be active when users are viewing channels. Always stop sync when leaving channels to optimize resource usage and prevent quota limits.

Implementation Guide

Start and stop receipt synchronization for channelsImplement basic receipt sync lifecycle management to track message status in real-time while users are actively viewing conversations.

Core Operations

OperationPurposeWhen to Use
startMessageReceiptSyncBegin tracking receipts for a channelUser enters chat screen
stopMessageReceiptSyncEnd receipt trackingUser leaves chat screen

Code Examples

import AmitySDK

let subChannelRepository = AmitySubChannelRepository(client: client)

class ChatViewController: UIViewController {
    private let subChannelId: String
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // Start receipt sync when user enters chat
        Task {
            do {
                try await subChannelRepository.startMessageReceiptSync(subChannelId: subChannelId)
                print("Receipt sync started for channel: \(subChannelId)")
            } catch {
                print("Failed to start receipt sync: \(error)")
                handleReceiptSyncError(error)
            }
        }
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        
        // Stop receipt sync when user leaves chat
        Task {
            do {
                try await subChannelRepository.stopMessageReceiptSync(subChannelId: subChannelId)
                print("Receipt sync stopped for channel: \(subChannelId)")
            } catch {
                print("Failed to stop receipt sync: \(error)")
            }
        }
    }
    
    private func handleReceiptSyncError(_ error: Error) {
        // Graceful error handling
        DispatchQueue.main.async {
            // Show user-friendly error message
            self.showErrorAlert("Unable to sync message status. Some features may be limited.")
        }
    }
}
Automatic Cleanup: Receipt sync automatically stops after one minute of network disconnection. When connection is re-established, sync resumes automatically.

Sync Management Strategies

Best Practices

Implementation Strategy: Start with basic lifecycle management (start sync on enter, stop on exit), then add advanced error handling and monitoring. Focus on resource efficiency to prevent quota issues and ensure scalable operation.