For 2024, you use the "token" method which is dead easy.
For your server you need to make a private key. You do that instantly with one click on Apple's web site here .. https://developer.apple.com/account/resources/authkeys/add ie click "keys" on the left menu on the Apple "certs/ids/profiles" screen.
That's on DEVELOPER apple, not the weird-ass "appstoreconnect" site.
Note you don't have to use "keychain access" or anything. You just tap a button on that page and it gives you an ID and a private key. (Make as many as you want, perhaps for different servers, or if you just feel like it, tap all day.)
It just downloads it as a .p8 file, which is simply the plain text of the key, open in any text editor. (Not to be confused with, say, a .p12 file which is totally different and binary.)
Again, that is you making a key for your server to use. Not to be confused with the similar process of "adding a capability" to an app id when you click "identifiers" on that left menu.
wrong!
Your private key will look like this
let keystring = `-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49Aas8d76as8das687asd687asd68as8brwUIWA46qcXis
zCu6dbd4s8d7b5s86gf98ugtr28re7089a7d6tbvpiiui524kyfpq9861eFJP7we
eE7rX4182609457ohgyj3lhgp98wfb698bfg69287f2k4htgwpo876grwo7XDklz
9fdg689d
-----END PRIVATE KEY-----`
your key id will look like this
let keyId = "CTU7XXBPRH"
Note that it used to be a PITA to find the keyId, it's now literally in the filename! of the .p8 file, or indeed it openly tells you the keyId on the apple web page, forever, once you have created the key, no stress.
Finally your Apple team id "Y3DEXAMPLE" is AT LAST listed plainly by Apple at https://developer.apple.com/account
Note that you ONLY NEED ONE KEY, it works for both normal push and "development aka sandbox" push.
To repeat there ARE NOT two different keys for production/sandbox, it's "just a key" so that Apple servers know your server.
To send push on an ordinary Node server on AWS, use the outstanding new long established APNS2 https://www.npmjs.com/package/apns2
ubuntu@your-server:~$] npm install apns2 -g
Send a push:
const { ApnsClient } = require('apns2')
const client = new ApnsClient({ ...
import { Notification } = require('apns2')
const bn = new Notification(deviceToken, {alert: 'Sup'})
It's that easy.
Tips:
Don't forget the damned "development/sandbox" pushes only work ON AN IPHONE TETHERED TO YOUR MAC/XCODE - !!!!!
Note that the so-called development/sandbox pushes are often flakey. They don't arrive for hours, they don't arrive at all, they simply do not work in certain regions.
Don't forget that it is TOTALLY OK to use the so-called "production" ones, simply, with a TestFlight app.
So
- Make a build
- Push to TestFlight. Wait a couple minutes as usual until the build comes through,
- You must install it from TestFlight to your physical phone
- You will now get all the pushes - instantly!
Whereas if you
- Make a build
- Just build/run to your tethered iPhone
- You do NOT get any pushes.
- It's true that you can get the so-called "development/sandbox" pushes, but they are often flakey.
(With APNS2, if you do want to try "development aka sandbox" pushes, see the last line of the doco page: https://www.npmjs.com/package/apns2 )