How Apple push works
Every push to an iPhone, iPad or Mac goes through Apple Push Notification service (APNs). Here's what sending one takes on your own, and what it takes with Pushwren.
- 1 Upload your .p8 key
- 2 Add the Swift package
- 3 Send with one call
The pieces
- Your app asks iOS for a device token. Each install gets its own token, and a token works only in the environment it was made for (Registering your app with APNs).
- APNs is Apple's service. It takes a push for a device token and delivers it to the device when it can.
- Besides alerts and silent pushes, APNs updates Live Activities, the Lock Screen views that track an order or a game, with tokens of their own (Starting and updating Live Activities with ActivityKit push notifications). The Live Activities guide shows how Pushwren sends them.
- Requests to APNs are signed with your APNs key, the .p8 file you make in your Apple Developer account. One key works for all your apps and both environments (Establishing a token-based connection to APNs). The APNs key guide shows how to make one.
Sandbox and production
APNs has two environments. Apps you run from Xcode get sandbox tokens; TestFlight and App Store builds get production tokens. A push sent to the wrong environment fails with BadDeviceToken. This is the most common reason a push that worked in development doesn't arrive in TestFlight. Pushwren's SDK reports which environment each device uses, and Pushwren sends each push to the right one.
What APNs confirms, and what it doesn't
When APNs answers 200, it has accepted the push. It doesn't tell you whether the device showed it: the device may be off, notifications may be turned off, or Focus may hold it. APNs reports a dead token only when you send to it, with 410 Unregistered (Handling notification responses from APNs). That's why Pushwren's delivery log says "accepted", never "delivered".
Why sending needs a server
The APNs key can send to every install of your apps, so it must never ship inside an app. Something you run has to hold it, sign each request and talk to APNs over HTTP/2 (Sending notification requests to APNs). With Pushwren, that something is Pushwren: your server makes one HTTPS call, or you send from the portal. The quickstart takes you from no account to a push on your phone.