Skip to content
Merged
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
8 changes: 7 additions & 1 deletion Sources/APNS/APNSBroadcastClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public final class APNSBroadcastClient<Decoder: APNSJSONDecoder & Sendable, Enco
/// The broadcast environment to use.
private let environment: APNSBroadcastEnvironment

/// The app's bundle identifier used in the API path.
private let bundleID: String

/// The ``HTTPClient`` used by the APNS broadcast client.
private let httpClient: HTTPClient

Expand Down Expand Up @@ -62,19 +65,22 @@ public final class APNSBroadcastClient<Decoder: APNSJSONDecoder & Sendable, Enco
/// - Parameters:
/// - authenticationMethod: The authentication method to use.
/// - environment: The broadcast environment (production or sandbox).
/// - bundleID: The app's bundle identifier (e.g., "com.example.myapp").
/// - eventLoopGroupProvider: Specify how EventLoopGroup will be created.
/// - responseDecoder: The decoder for the responses from APNs.
/// - requestEncoder: The encoder for the requests to APNs.
/// - byteBufferAllocator: The `ByteBufferAllocator`.
public init(
authenticationMethod: APNSClientConfiguration.AuthenticationMethod,
environment: APNSBroadcastEnvironment,
bundleID: String,
eventLoopGroupProvider: NIOEventLoopGroupProvider,
responseDecoder: Decoder,
requestEncoder: Encoder,
byteBufferAllocator: ByteBufferAllocator = .init()
) {
self.environment = environment
self.bundleID = bundleID
self.byteBufferAllocator = byteBufferAllocator
self.responseDecoder = responseDecoder
self.requestEncoder = requestEncoder
Expand Down Expand Up @@ -140,7 +146,7 @@ extension APNSBroadcastClient {
}

// Build the request URL
let requestURL = "\(self.environment.url):\(self.environment.port)\(request.operation.path)"
let requestURL = "\(self.environment.url):\(self.environment.port)/1/apps/\(self.bundleID)\(request.operation.path)"

// Create HTTP request
var httpClientRequest = HTTPClientRequest(url: requestURL)
Expand Down
15 changes: 8 additions & 7 deletions Sources/APNSTestServer/APNSTestServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,21 @@ public final class APNSTestServer: @unchecked Sendable {
// Parse the URI
let components = uri.split(separator: "/")

// Broadcast channel endpoints
// Broadcast channel endpoints: /1/apps/{bundleID}/channels[/{channelID}]
// Expected format: ["1", "apps", "{bundleID}", "channels"] or ["1", "apps", "{bundleID}", "channels", "{channelID}"]
switch (method, components.count) {
case (.POST, 1) where components[0] == "channels":
case (.POST, 4) where components[0] == "1" && components[1] == "apps" && components[3] == "channels":
return handleCreateChannel(body: body)

case (.GET, 1) where components[0] == "channels":
case (.GET, 4) where components[0] == "1" && components[1] == "apps" && components[3] == "channels":
return handleListChannels()

case (.GET, 2) where components[0] == "channels":
let channelID = String(components[1])
case (.GET, 5) where components[0] == "1" && components[1] == "apps" && components[3] == "channels":
let channelID = String(components[4])
return handleReadChannel(channelID: channelID)

case (.DELETE, 2) where components[0] == "channels":
let channelID = String(components[1])
case (.DELETE, 5) where components[0] == "1" && components[1] == "apps" && components[3] == "channels":
let channelID = String(components[4])
return handleDeleteChannel(channelID: channelID)

// Regular push notification endpoint: POST /3/device/{token}
Expand Down
1 change: 1 addition & 0 deletions Tests/APNSTests/Broadcast/APNSBroadcastClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class APNSBroadcastClientTests: XCTestCase {
teamIdentifier: "MY_TEAM_ID"
),
environment: .custom(url: "http://127.0.0.1", port: serverPort),
bundleID: "com.example.testapp",
eventLoopGroupProvider: .createNew,
responseDecoder: JSONDecoder(),
requestEncoder: JSONEncoder()
Expand Down