diff --git a/README.md b/README.md index 9d586f6..b875534 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 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 + +```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 c1ac664..85cb9ce 100644 --- a/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift +++ b/Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift @@ -41,5 +41,30 @@ 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`. + @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) + } }