NotificationCleanupConfig

public struct NotificationCleanupConfig : Sendable

Configuration for automatic cleanup of push notifications.

This configuration allows for managing storage by removing old or excessive notifications. Cleanup can be performed automatically when new notifications are processed, or manually by calling the cleanup methods on the PushClient.

Cleanup Strategies

  • None: No automatic cleanup is performed
  • Count-Based: Removes oldest notifications when count exceeds maximum
  • Age-Based: Removes notifications older than specified age
  • Hybrid: Applies both count-based and age-based cleanup

Usage Examples

// Count-based cleanup (default)
let config1 = NotificationCleanupConfig()

// Age-based cleanup (remove after 7 days)
let config2 = NotificationCleanupConfig(
    cleanupMode: .ageBased,
    maxNotificationAgeDays: 7
)

// Hybrid cleanup
let config3 = NotificationCleanupConfig(
    cleanupMode: .hybrid,
    maxStoredNotifications: 50,
    maxNotificationAgeDays: 14
)

// No cleanup
let config4 = NotificationCleanupConfig(cleanupMode: .none)
  • Cleanup mode determines how notifications are cleaned up.

    See more

    Declaration

    Swift

    public enum CleanupMode : String, CaseIterable, Sendable

Properties

  • The cleanup mode to use.

    Declaration

    Swift

    public let cleanupMode: CleanupMode
  • Maximum number of notifications to store per credential (for count-based cleanup).

    When the number of notifications exceeds this value, the oldest notifications will be removed to bring the count back down to this limit.

    Default value is 100 notifications.

    Declaration

    Swift

    public let maxStoredNotifications: Int
  • Maximum age of notifications in days (for age-based cleanup).

    Notifications older than this will be removed during cleanup. The age is calculated from the notification’s createdAt timestamp.

    Default value is 30 days.

    Declaration

    Swift

    public let maxNotificationAgeDays: Int

Initialization

  • Creates a new notification cleanup configuration.

    Example

    let config = NotificationCleanupConfig(
        cleanupMode: .hybrid,
        maxStoredNotifications: 50,
        maxNotificationAgeDays: 14
    )
    

    Declaration

    Swift

    public init(
        cleanupMode: CleanupMode = .countBased,
        maxStoredNotifications: Int = 100,
        maxNotificationAgeDays: Int = 30
    )

    Parameters

    cleanupMode

    The cleanup mode to use. Defaults to .countBased.

    maxStoredNotifications

    Maximum notifications to store. Defaults to 100.

    maxNotificationAgeDays

    Maximum age in days. Defaults to 30.

Factory Methods

  • Creates a default notification cleanup configuration.

    The default configuration uses count-based cleanup with a maximum of 100 notifications and a 30-day age limit.

    Example

    let config = NotificationCleanupConfig.default()
    // Equivalent to: NotificationCleanupConfig()
    

    Declaration

    Swift

    public static func `default`() -> NotificationCleanupConfig

    Return Value

    A configuration with default settings.

  • Creates a configuration with no automatic cleanup.

    Example

    let config = NotificationCleanupConfig.none()
    

    Declaration

    Swift

    public static func none() -> NotificationCleanupConfig

    Return Value

    A configuration with cleanup mode set to .none.

  • Creates a configuration for count-based cleanup.

    Example

    let config = NotificationCleanupConfig.countBased(maxNotifications: 50)
    

    Declaration

    Swift

    public static func countBased(maxNotifications: Int = 100) -> NotificationCleanupConfig

    Parameters

    maxNotifications

    Maximum number of notifications to keep. Defaults to 100.

    Return Value

    A configuration with count-based cleanup.

  • Creates a configuration for age-based cleanup.

    Example

    let config = NotificationCleanupConfig.ageBased(maxAgeDays: 7)
    

    Declaration

    Swift

    public static func ageBased(maxAgeDays: Int = 30) -> NotificationCleanupConfig

    Parameters

    maxAgeDays

    Maximum age in days. Defaults to 30.

    Return Value

    A configuration with age-based cleanup.

  • Creates a configuration for hybrid cleanup.

    Example

    let config = NotificationCleanupConfig.hybrid(
        maxNotifications: 50,
        maxAgeDays: 14
    )
    

    Declaration

    Swift

    public static func hybrid(
        maxNotifications: Int = 100,
        maxAgeDays: Int = 30
    ) -> NotificationCleanupConfig

    Parameters

    maxNotifications

    Maximum number of notifications to keep. Defaults to 100.

    maxAgeDays

    Maximum age in days. Defaults to 30.

    Return Value

    A configuration with hybrid cleanup.