From 825cb76dd1ecfdeb3e847b139430db06d93b99bb Mon Sep 17 00:00:00 2001 From: Chris Tibbs Date: Mon, 15 Dec 2025 12:31:41 -0500 Subject: [PATCH 1/3] APNSClient Start live activity convenience method --- README.md | 26 +++++++++++++++++++ .../APNSClient+LiveActivity.swift | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/README.md b/README.md index 9d586f6f..cb59dd07 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,32 @@ try await client.sendAlertNotification( ) ``` +## Sending Live Activity Start +To successfully start a live activity: +- `Attributes` and `ContentState` must match the live activity configuration +- `alert` must contain a title, body, and sound + - title and body are visible to the device's paired Apple Watch when starting the live activity + +```swift +let response = try await client.sendStartLiveActivityNotification( + .init ( + expiration: .immediately, + priority: .immediately, + appID: "com.app.bundle", + contentState: contentState, + timestamp: Int(Date().timeIntervalSince1970), + attributes: attributes, + attributesType: "YourActivityAttributes", + alert: .init( + title: .raw("Your title"), + body: .raw(Your body), + sound: .fileName("default.aiff") + ) + ), + pushToStartToken: pushToStartToken +) +``` + ## Sending Live Activity Update / End It requires sending `ContentState` matching with the live activity configuration to successfully update activity state. `ContentState` needs to conform to `Encodable` and `Sendable`. diff --git a/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift b/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift index c1ac664d..5fabefda 100644 --- a/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift +++ b/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift @@ -41,5 +41,31 @@ extension APNSClientProtocol { ) return try await send(request) } + + /// Sends a notification to start a live activity. + /// + /// - Parameters: + /// - notification: The notification to send. + /// - pushToStartToken: The hexadecimal bytes use to start a live on a device. Your app receives the bytes for this activity token + /// from the `pushToStartTokenUpdates` async stream on `Activity`. + @available(iOS 16.1, *) + @discardableResult + @inlinable + public func sendStartLiveActivityNotification( + _ notification: APNSStartLiveActivityNotification, + pushToStartToken: String + ) async throws -> APNSResponse { + let request = APNSRequest( + message: notification, + deviceToken: pushToStartToken, + pushType: .liveactivity, + expiration: notification.expiration, + priority: notification.priority, + apnsID: notification.apnsID, + topic: notification.topic, + collapseID: nil + ) + return try await send(request) + } } From 201db1fb123e4a63e63d5afb5f8a65c04afd5e96 Mon Sep 17 00:00:00 2001 From: Chris Tibbs Date: Mon, 15 Dec 2025 12:57:52 -0500 Subject: [PATCH 2/3] Better start instructions in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb59dd07..b875534d 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ try await client.sendAlertNotification( ## Sending Live Activity Start To successfully start a live activity: -- `Attributes` and `ContentState` must match the live activity configuration +- `Attributes` and `ContentState` must match the live activity attributes provided in `attributesType` - `alert` must contain a title, body, and sound - title and body are visible to the device's paired Apple Watch when starting the live activity From 98658c4316acc028d09336dee122cfc2d6caab3e Mon Sep 17 00:00:00 2001 From: Chris Tibbs Date: Mon, 15 Dec 2025 12:58:17 -0500 Subject: [PATCH 3/3] Remove unnecessary iOS 16.1 check --- Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift b/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift index 5fabefda..85cb9cec 100644 --- a/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift +++ b/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift @@ -48,7 +48,6 @@ extension APNSClientProtocol { /// - notification: The notification to send. /// - pushToStartToken: The hexadecimal bytes use to start a live on a device. Your app receives the bytes for this activity token /// from the `pushToStartTokenUpdates` async stream on `Activity`. - @available(iOS 16.1, *) @discardableResult @inlinable public func sendStartLiveActivityNotification(