From c436f32ae4020f993dd1a9597488c6c76cbd2349 Mon Sep 17 00:00:00 2001 From: emmikkelsen Date: Thu, 29 May 2025 20:40:06 -0500 Subject: [PATCH 1/3] Add alert content to notification --- .../APNSLiveActivityNotification.swift | 8 +++++- ...NSLiveActivityNotificationAPSStorage.swift | 6 ++++- .../APNSLiveActivityNotificationTests.swift | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift index 358d16b..e6e80ff 100644 --- a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift +++ b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift @@ -100,6 +100,7 @@ public struct APNSLiveActivityNotification: /// - apnsID: A canonical UUID that identifies the notification. /// - contentState: Updated content-state of live activity /// - event: event type e.g. update + /// - alert: Optional alert content for the notification. /// - timestamp: Timestamp when sending notification /// - dismissalDate: Timestamp when to dismiss live notification when sent with `end`, if in the past /// dismiss immediately @@ -109,6 +110,7 @@ public struct APNSLiveActivityNotification: appID: String, contentState: ContentState, event: APNSLiveActivityNotificationEvent, + alert: APNSAlertNotificationContent? = nil, timestamp: Int, dismissalDate: APNSLiveActivityDismissalDate = .none, apnsID: UUID? = nil @@ -119,6 +121,7 @@ public struct APNSLiveActivityNotification: topic: appID + ".push-type.liveactivity", contentState: contentState, event: event, + alert: alert, timestamp: timestamp, dismissalDate: dismissalDate ) @@ -136,6 +139,7 @@ public struct APNSLiveActivityNotification: /// - apnsID: A canonical UUID that identifies the notification. /// - contentState: Updated content-state of live activity /// - event: event type e.g. update + /// - alert: Optional alert content for the notification. /// - timestamp: Timestamp when sending notification /// - dismissalDate: Timestamp when to dismiss live notification when sent with `end`, if in the past /// dismiss immediately @@ -146,6 +150,7 @@ public struct APNSLiveActivityNotification: apnsID: UUID? = nil, contentState: ContentState, event: APNSLiveActivityNotificationEvent, + alert: APNSAlertNotificationContent? = nil, timestamp: Int, dismissalDate: APNSLiveActivityDismissalDate = .none ) { @@ -153,7 +158,8 @@ public struct APNSLiveActivityNotification: timestamp: timestamp, event: event.rawValue, contentState: contentState, - dismissalDate: dismissalDate.dismissal + dismissalDate: dismissalDate.dismissal, + alert: alert ) self.apnsID = apnsID self.expiration = expiration diff --git a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift index 7bde976..fa44a27 100644 --- a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift +++ b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift @@ -18,22 +18,26 @@ struct APNSLiveActivityNotificationAPSStorage Date: Wed, 9 Jul 2025 21:48:46 -0500 Subject: [PATCH 2/3] Add stale-date key to live activity --- .../APNSLiveActivityNotification.swift | 11 ++++++-- ...NSLiveActivityNotificationAPSStorage.swift | 4 +++ .../APNSLiveActivityNotificationTests.swift | 25 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift index e6e80ff..fb6934a 100644 --- a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift +++ b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift @@ -104,6 +104,7 @@ public struct APNSLiveActivityNotification: /// - timestamp: Timestamp when sending notification /// - dismissalDate: Timestamp when to dismiss live notification when sent with `end`, if in the past /// dismiss immediately + /// - staleDate: Timestamp when the notification is marked as stale public init( expiration: APNSNotificationExpiration, priority: APNSPriority, @@ -113,17 +114,20 @@ public struct APNSLiveActivityNotification: alert: APNSAlertNotificationContent? = nil, timestamp: Int, dismissalDate: APNSLiveActivityDismissalDate = .none, + staleDate: Int? = nil, apnsID: UUID? = nil ) { self.init( expiration: expiration, priority: priority, topic: appID + ".push-type.liveactivity", + apnsID: apnsID, contentState: contentState, event: event, alert: alert, timestamp: timestamp, - dismissalDate: dismissalDate + dismissalDate: dismissalDate, + staleDate: staleDate, ) } @@ -143,6 +147,7 @@ public struct APNSLiveActivityNotification: /// - timestamp: Timestamp when sending notification /// - dismissalDate: Timestamp when to dismiss live notification when sent with `end`, if in the past /// dismiss immediately + /// - staleDate: Timestamp when the notification is marked as stale public init( expiration: APNSNotificationExpiration, priority: APNSPriority, @@ -152,13 +157,15 @@ public struct APNSLiveActivityNotification: event: APNSLiveActivityNotificationEvent, alert: APNSAlertNotificationContent? = nil, timestamp: Int, - dismissalDate: APNSLiveActivityDismissalDate = .none + dismissalDate: APNSLiveActivityDismissalDate = .none, + staleDate: Int? = nil ) { self.aps = APNSLiveActivityNotificationAPSStorage( timestamp: timestamp, event: event.rawValue, contentState: contentState, dismissalDate: dismissalDate.dismissal, + staleDate: staleDate, alert: alert ) self.apnsID = apnsID diff --git a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift index fa44a27..5b96a0c 100644 --- a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift +++ b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotificationAPSStorage.swift @@ -18,6 +18,7 @@ struct APNSLiveActivityNotificationAPSStorage Date: Wed, 9 Jul 2025 22:10:25 -0500 Subject: [PATCH 3/3] Remove trailing comma --- .../APNSCore/LiveActivity/APNSLiveActivityNotification.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift index fb6934a..7127a40 100644 --- a/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift +++ b/Sources/APNSCore/LiveActivity/APNSLiveActivityNotification.swift @@ -127,7 +127,7 @@ public struct APNSLiveActivityNotification: alert: alert, timestamp: timestamp, dismissalDate: dismissalDate, - staleDate: staleDate, + staleDate: staleDate ) }