A server that lets your clients send themselves push notifications.
The server uses the following env variables:
A redis url. If you don't set this, the server will crash on start.
REDIS_URL="redis://localhost:6379" # Example
The identifier for the key for your push notifications. You can get this from https://developer.apple.com/help/account/manage-keys/get-a-key-identifier.
KEY_IDENTIFIER="ABC1234D56" # Example
The team identifier you registered for the key for.
TEAM_IDENTIFIER="A123BC45D6" # Example
The contents of the .p8 key you got for APNS.
PRIVATE_KEY="$(cat ./AuthKey_ABC1234D56.p8)" # Example
The apns-topic
to send to APNS. This is almost always your bundle identifier.
Pushes sent to the server without this topic will be ignored.
TOPIC="com.example.apnea" # Example
The port to run the server on. Defaults to 4567.
PORT=8080 # Example
Get an APNEAClient
by passing it the URL of your APNEA server.
let client = APNEAClient(url: URL(string: "http://localhost:4567")!)
Send yourself a push notification:
try await client.schedule(.init(
// Every push needs an ID.
id: UUID(),
// This is the message content. It's still sort of in flux.
message: .alert("hello world"),
// The device token you get from application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
deviceToken: pushToken.map { String(format: "%02x", $0) }.joined(),
// APNS Header fields (https://developer.apple.com/documentation/usernotifications/sending-notification-requests-to-apns#Send-a-POST-request-to-APNs)
pushType: .alert,
expiration: .immediately,
priority: .immediately,
apnsID: nil,
topic: Bundle.main.bundleIdentifier!,
collapseID: nil,
// Send the push in 5 seconds
schedule: .once(on: Date().advanced(by: 5))
))