Skip to content

Commit 3b9b89a

Browse files
MyrronthTobias Kreß
andauthored
Add staleDate to APNSStartLiveActivityNotification (#227)
Co-authored-by: Tobias Kreß <tobias.kress@intive.com>
1 parent 01b731f commit 3b9b89a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Sources/APNSCore/LiveActivity/APNSStartLiveActivityNotification.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public struct APNSStartLiveActivityNotification<Attributes: Encodable & Sendable
102102
/// - timestamp: Timestamp when sending notification
103103
/// - dismissalDate: Timestamp when to dismiss live notification when sent with `end`, if in the past
104104
/// dismiss immediately
105+
/// - staleDate: Timestamp when the notification is marked as stale
105106
/// - apnsID: A canonical UUID that identifies the notification.
106107
/// - attributes: The ActivityAttributes of the live activity to start
107108
/// - attributesType: The type name of the ActivityAttributes you want to send
@@ -113,6 +114,7 @@ public struct APNSStartLiveActivityNotification<Attributes: Encodable & Sendable
113114
contentState: ContentState,
114115
timestamp: Int,
115116
dismissalDate: APNSLiveActivityDismissalDate = .none,
117+
staleDate: Int? = nil,
116118
apnsID: UUID? = nil,
117119
attributes: Attributes,
118120
attributesType: String,
@@ -122,6 +124,7 @@ public struct APNSStartLiveActivityNotification<Attributes: Encodable & Sendable
122124
timestamp: timestamp,
123125
contentState: contentState,
124126
dismissalDate: dismissalDate.dismissal,
127+
staleDate: staleDate,
125128
alert: alert,
126129
attributes: attributes,
127130
attributesType: attributesType

Sources/APNSCore/LiveActivity/APNSStartLiveActivityNotificationAPSStorage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct APNSStartLiveActivityNotificationAPSStorage<Attributes: Encodable & Senda
2020
case event = "event"
2121
case contentState = "content-state"
2222
case dismissalDate = "dismissal-date"
23+
case staleDate = "stale-date"
2324
case alert = "alert"
2425
case attributes = "attributes"
2526
case attributesType = "attributes-type"
@@ -29,6 +30,7 @@ struct APNSStartLiveActivityNotificationAPSStorage<Attributes: Encodable & Senda
2930
var event: String = "start"
3031
var contentState: ContentState
3132
var dismissalDate: Int?
33+
var staleDate: Int?
3234
var alert: APNSAlertNotificationContent
3335
var attributes: Attributes
3436
var attributesType: String
@@ -37,13 +39,15 @@ struct APNSStartLiveActivityNotificationAPSStorage<Attributes: Encodable & Senda
3739
timestamp: Int,
3840
contentState: ContentState,
3941
dismissalDate: Int?,
42+
staleDate: Int?,
4043
alert: APNSAlertNotificationContent,
4144
attributes: Attributes,
4245
attributesType: String
4346
) {
4447
self.timestamp = timestamp
4548
self.contentState = contentState
4649
self.dismissalDate = dismissalDate
50+
self.staleDate = staleDate
4751
self.alert = alert
4852
self.attributes = attributes
4953
self.attributesType = attributesType

Tests/APNSTests/LiveActivity/APNSLiveActivityNotificationTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ final class APNSLiveActivityNotificationTests: XCTestCase {
106106
appID: "test.app.id",
107107
contentState: State(),
108108
timestamp: 1_672_680_658,
109+
staleDate: 1_672_680_800,
109110
attributes: Attributes(),
110111
attributesType: "Attributes",
111112
alert: .init(title: .raw("Hi"), body: .raw("Hello"))
@@ -115,7 +116,8 @@ final class APNSLiveActivityNotificationTests: XCTestCase {
115116
let data = try encoder.encode(notification)
116117

117118
let expectedJSONString = """
118-
{"aps":{"event":"start", "alert": { "title": "Hi", "body": "Hello" }, "attributes-type": "Attributes", "attributes": {"name":"Test Attribute"},"content-state":{"string":"Test","number":123},"timestamp":1672680658}}
119+
{"aps":{"event":"start", "alert": { "title": "Hi", "body": "Hello" }, "attributes-type": "Attributes", "attributes": {"name":"Test Attribute"},"content-state":{"string":"Test","number":123},"timestamp":1672680658,
120+
"stale-date":1672680800}}
119121
"""
120122

121123
let jsonObject1 = try JSONSerialization.jsonObject(with: data) as! NSDictionary

0 commit comments

Comments
 (0)