From 96bfdc1beb37a500c153d321a4f4d2769feb030b Mon Sep 17 00:00:00 2001 From: Harlan Haskins Date: Sun, 18 May 2025 13:01:43 -0400 Subject: [PATCH] Mark APNSResponse and APNSErrorResponse as Sendable This ensures you can send notifications within an actor isolated context. Fixes #217 --- Sources/APNSCore/APNSErrorResponse.swift | 2 +- Sources/APNSCore/APNSResponse.swift | 2 +- Tests/APNSTests/APNSClientTests.swift | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Sources/APNSCore/APNSErrorResponse.swift b/Sources/APNSCore/APNSErrorResponse.swift index 3e42e15c..26d28944 100644 --- a/Sources/APNSCore/APNSErrorResponse.swift +++ b/Sources/APNSCore/APNSErrorResponse.swift @@ -15,7 +15,7 @@ /// A struct for the error response of APNs. /// /// This is just used to decode the JSON and should not be exposed. -public struct APNSErrorResponse: Codable { +public struct APNSErrorResponse: Codable, Sendable { /// The error code indicating the reason for the failure. public var reason: String diff --git a/Sources/APNSCore/APNSResponse.swift b/Sources/APNSCore/APNSResponse.swift index fe5c10e7..0963485a 100644 --- a/Sources/APNSCore/APNSResponse.swift +++ b/Sources/APNSCore/APNSResponse.swift @@ -15,7 +15,7 @@ import struct Foundation.UUID /// The response of a successful APNs request. -public struct APNSResponse: Hashable { +public struct APNSResponse: Hashable, Sendable { /// The same value as the `apnsID` send in the request. /// /// Use this value to identify the notification. If you don’t specify an `apnsID` in your request, diff --git a/Tests/APNSTests/APNSClientTests.swift b/Tests/APNSTests/APNSClientTests.swift index d04679ca..1f2727f2 100644 --- a/Tests/APNSTests/APNSClientTests.swift +++ b/Tests/APNSTests/APNSClientTests.swift @@ -50,3 +50,18 @@ final class APNSClientTests: XCTestCase { -----END PRIVATE KEY----- """ } + +// This doesn't perform any runtime tests, it just ensures the call to sendAlertNotification +// compiles when called within an actor's isolation context. +actor TestActor { + func sendAlert(client: APNSClient) async throws { + let notification = APNSAlertNotification( + alert: .init(title: .raw("title")), + expiration: .immediately, + priority: .immediately, + topic: "", + payload: "" + ) + try await client.sendAlertNotification(notification, deviceToken: "") + } +}