Skip to content

Commit 234d745

Browse files
authored
Add bundle id for broadcast URL (#234)
1 parent 1af081b commit 234d745

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Sources/APNS/APNSBroadcastClient.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public final class APNSBroadcastClient<Decoder: APNSJSONDecoder & Sendable, Enco
2929
/// The broadcast environment to use.
3030
private let environment: APNSBroadcastEnvironment
3131

32+
/// The app's bundle identifier used in the API path.
33+
private let bundleID: String
34+
3235
/// The ``HTTPClient`` used by the APNS broadcast client.
3336
private let httpClient: HTTPClient
3437

@@ -62,19 +65,22 @@ public final class APNSBroadcastClient<Decoder: APNSJSONDecoder & Sendable, Enco
6265
/// - Parameters:
6366
/// - authenticationMethod: The authentication method to use.
6467
/// - environment: The broadcast environment (production or sandbox).
68+
/// - bundleID: The app's bundle identifier (e.g., "com.example.myapp").
6569
/// - eventLoopGroupProvider: Specify how EventLoopGroup will be created.
6670
/// - responseDecoder: The decoder for the responses from APNs.
6771
/// - requestEncoder: The encoder for the requests to APNs.
6872
/// - byteBufferAllocator: The `ByteBufferAllocator`.
6973
public init(
7074
authenticationMethod: APNSClientConfiguration.AuthenticationMethod,
7175
environment: APNSBroadcastEnvironment,
76+
bundleID: String,
7277
eventLoopGroupProvider: NIOEventLoopGroupProvider,
7378
responseDecoder: Decoder,
7479
requestEncoder: Encoder,
7580
byteBufferAllocator: ByteBufferAllocator = .init()
7681
) {
7782
self.environment = environment
83+
self.bundleID = bundleID
7884
self.byteBufferAllocator = byteBufferAllocator
7985
self.responseDecoder = responseDecoder
8086
self.requestEncoder = requestEncoder
@@ -140,7 +146,7 @@ extension APNSBroadcastClient {
140146
}
141147

142148
// Build the request URL
143-
let requestURL = "\(self.environment.url):\(self.environment.port)\(request.operation.path)"
149+
let requestURL = "\(self.environment.url):\(self.environment.port)/1/apps/\(self.bundleID)\(request.operation.path)"
144150

145151
// Create HTTP request
146152
var httpClientRequest = HTTPClientRequest(url: requestURL)

Sources/APNSTestServer/APNSTestServer.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,21 @@ public final class APNSTestServer: @unchecked Sendable {
129129
// Parse the URI
130130
let components = uri.split(separator: "/")
131131

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

137-
case (.GET, 1) where components[0] == "channels":
138+
case (.GET, 4) where components[0] == "1" && components[1] == "apps" && components[3] == "channels":
138139
return handleListChannels()
139140

140-
case (.GET, 2) where components[0] == "channels":
141-
let channelID = String(components[1])
141+
case (.GET, 5) where components[0] == "1" && components[1] == "apps" && components[3] == "channels":
142+
let channelID = String(components[4])
142143
return handleReadChannel(channelID: channelID)
143144

144-
case (.DELETE, 2) where components[0] == "channels":
145-
let channelID = String(components[1])
145+
case (.DELETE, 5) where components[0] == "1" && components[1] == "apps" && components[3] == "channels":
146+
let channelID = String(components[4])
146147
return handleDeleteChannel(channelID: channelID)
147148

148149
// Regular push notification endpoint: POST /3/device/{token}

Tests/APNSTests/Broadcast/APNSBroadcastClientTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ final class APNSBroadcastClientTests: XCTestCase {
3838
teamIdentifier: "MY_TEAM_ID"
3939
),
4040
environment: .custom(url: "http://127.0.0.1", port: serverPort),
41+
bundleID: "com.example.testapp",
4142
eventLoopGroupProvider: .createNew,
4243
responseDecoder: JSONDecoder(),
4344
requestEncoder: JSONEncoder()

0 commit comments

Comments
 (0)