Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
25 changes: 25 additions & 0 deletions Sources/APNSCore/LiveActivity/APNSClient+LiveActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attributes: Encodable & Sendable, ContentState: Encodable & Sendable>(
_ notification: APNSStartLiveActivityNotification<Attributes, ContentState>,
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)
}
}