Mark Notification Tray Seen

Global Tray Tracking

Update the tray’s seen timestamp on server when user visits the Notification Tray screen

Badge Management

Control UI badge indicators based on global seen status

Overview

Use markNotificationTraySeen() to update the tray’s seen timestamp on the server when the user visits the Notification Tray screen. This method supports global-level read tracking, separate from per-item seen state. Once invoked, future calls to getNotificationTraySeen() will return the new isSeen value. It is recommended to call this method as soon as the tray UI is opened.
This method updates the global tray seen state, not individual notification items. Use markSeen() on individual items for fine-grained tracking.

Implementation Guide

import AmitySDK

class NotificationTrayViewController: UIViewController {
    private let repository = AmityNotificationTrayRepository()
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // Mark tray as seen when user opens it
        markTrayAsSeen()
    }
    
    private func markTrayAsSeen() {
        repository.markNotificationTraySeen { [weak self] result in
            DispatchQueue.main.async {
                switch result {
                case .success:
                    self?.updateGlobalBadgeState()
                case .failure(let error):
                    print("Failed to mark tray as seen: \(error)")
                }
            }
        }
    }
    
    private func updateGlobalBadgeState() {
        // Update global app badge
        NotificationCenter.default.post(
            name: .notificationTrayMarkedAsSeen,
            object: nil
        )
    }
}

Usage Patterns

Error Handling

Best Practices