Skip to content

Commit 311d977

Browse files
Mark APNSResponse and APNSErrorResponse as Sendable (#218)
This ensures you can send notifications within an actor isolated context. Fixes #217
1 parent cc8c715 commit 311d977

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Sources/APNSCore/APNSErrorResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// A struct for the error response of APNs.
1616
///
1717
/// This is just used to decode the JSON and should not be exposed.
18-
public struct APNSErrorResponse: Codable {
18+
public struct APNSErrorResponse: Codable, Sendable {
1919
/// The error code indicating the reason for the failure.
2020
public var reason: String
2121

Sources/APNSCore/APNSResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import struct Foundation.UUID
1616

1717
/// The response of a successful APNs request.
18-
public struct APNSResponse: Hashable {
18+
public struct APNSResponse: Hashable, Sendable {
1919
/// The same value as the `apnsID` send in the request.
2020
///
2121
/// Use this value to identify the notification. If you don’t specify an `apnsID` in your request,

Tests/APNSTests/APNSClientTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ final class APNSClientTests: XCTestCase {
5050
-----END PRIVATE KEY-----
5151
"""
5252
}
53+
54+
// This doesn't perform any runtime tests, it just ensures the call to sendAlertNotification
55+
// compiles when called within an actor's isolation context.
56+
actor TestActor {
57+
func sendAlert(client: APNSClient<JSONDecoder, JSONEncoder>) async throws {
58+
let notification = APNSAlertNotification(
59+
alert: .init(title: .raw("title")),
60+
expiration: .immediately,
61+
priority: .immediately,
62+
topic: "",
63+
payload: ""
64+
)
65+
try await client.sendAlertNotification(notification, deviceToken: "")
66+
}
67+
}

0 commit comments

Comments
 (0)