Skip to content

Conversation

@kylebrowning
Copy link
Member

@kylebrowning kylebrowning commented Oct 30, 2025

Implements support for Apple's broadcast push notification channels introduced in iOS 18, addressing #205.

Overview

This PR adds complete broadcast channel management functionality to APNSwift, allowing developers to create, read, update, and delete broadcast channels through Apple's broadcast API.

What's New

Core Implementation (APNSCore)

  • New types for broadcast channels:
    • APNSBroadcastEnvironment - Production/sandbox broadcast endpoints
    • APNSBroadcastChannel - Channel configuration model
    • APNSBroadcastChannelList - List of channel IDs
    • APNSBroadcastRequest - Generic request type with operation routing
    • APNSBroadcastResponse - Generic response type
    • APNSBroadcastMessageStoragePolicy - Enum for storage options
    • APNSBroadcastClientProtocol - Protocol with convenience methods

Client Implementation (APNS)

  • APNSBroadcastClient - Full-featured client supporting:
    • POST /channels - Create new broadcast channels
    • GET /channels - List all channels
    • GET /channels/{id} - Read channel details
    • DELETE /channels/{id} - Delete channels
    • Proper HTTP method routing and error handling

Test Infrastructure (APNSTestServer)

  • APNSBroadcastTestServer - Real SwiftNIO HTTP server that mocks Apple's broadcast API
    • In-memory channel storage
    • Full CRUD operation support
    • Proper error responses (404, 400)
    • Request ID generation

Tests

  • 13 new tests covering:
    • Unit tests for encoding/decoding broadcast types
    • Integration tests with mock server
    • Error handling and edge cases
  • All 38 tests pass (existing + new)

Usage Example

let client = APNSBroadcastClient(
authenticationMethod: .jwt(
privateKey: privateKey,
keyIdentifier: "KEY_ID",
teamIdentifier: "TEAM_ID"
),
environment: .production,
eventLoopGroupProvider: .createNew,
responseDecoder: JSONDecoder(),
requestEncoder: JSONEncoder()
)

// Create a broadcast channel
let channel = APNSBroadcastChannel(messageStoragePolicy: .mostRecentMessageStored)
let response = try await client.create(channel: channel)
let channelID = response.body.channelID!

// List all channels
let allChannels = try await client.readAllChannelIDs()

// Delete a channel
try await client.delete(channelID: channelID)

Implementation Details

  • Preserves API compatibility: Internal access control maintained to avoid breaking changes
  • Protocol-based design: Easy to mock and test in consumer code
  • Type-safe operations: Generic request/response types with proper Swift concurrency support
  • Comprehensive testing: Includes both unit and integration tests with a real NIO-based mock server

Changes from Original Branch

This PR builds on the work started in https://github.com/eliperkins/APNSwift/tree/channels but completes the implementation:

  • ✅ Fixed incomplete send() method
  • ✅ Added proper HTTP method routing (GET/POST/DELETE)
  • ✅ Correct endpoint construction for all operations
  • ✅ Added comprehensive tests
  • ✅ Created mock server for testing
  • ✅ Full documentation

Testing

Run all tests

swift test

Run only broadcast tests

swift test --filter Broadcast

Documentation

See BROADCAST_CHANNELS.md for:

  • Complete usage examples
  • Architecture decisions
  • Testing guide with mock server
  • Future enhancement ideas

Related

Closes #205

@kylebrowning kylebrowning changed the title Implement broadcast channels Add iOS 18+ Broadcast Push Notifications Support Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for broadcast push notifications, channels

2 participants