In the last chapter, you set up your app to be able to receive push notifications. The last piece that you’ll need in order to have your app receive a push notification is an Authentication Token used by Apple’s servers to trust your app. This token validates your server and makes sure that there’s always a secure connection between your backend and APNs.
Authentication token types
When Apple first started allowing sending push notifications, it used the PKCS #12 archive file format, also commonly known as the PFX format.
If you’ve ever worked with push notifications in the past, this file ends with the .p12 file extension.
This type of format was quite cumbersome to work with for multiple reasons:
They are only valid for a single year, requiring yearly “maintenance” of your certificates.
You need separate certificates for both production and development distributions.
You need separate certificates for every app you publish.
Apple does not provide the certificate in the “final” format you’ll actually need to send notifications, requiring you to run multiple openssl commands from Terminal for the multiple conversions; usually requiring a bit of research to remember how.
Around 2016, in order to work around the above problems, Apple started supporting the industry standard RFC 7519, better known as JSON Web Tokens, or JWT (jwt.io/). These tokens use the newer .p8 file extension.
Apple, of course, likes its own names and so all of its documentation on push notifications refers to these as Authentication Tokens. Changing to the newer format alleviated all the issues of the PFX file format as they do not need to be renewed, don’t differentiate between production and development, and can be used by all of your apps.
Unfortunately, Apple did very little other than say, “There it is!”, when it released it. Unless you already had experience with HTTP/2 and JWT, you were stuck. We’ll remedy that now!
Getting your Authentication Token
Creating the Authentication Token is a simple process that you only have to do once. In a browser of your choice, go to the Member Center (apple.co/2HRPzxv), and sign in with your Apple ID.
Moq hlomm Yaxufxeq in ddu scraej dbum ajjoorb, pheg sbubm Kevmyueb idc, widarnb, Yamu.
Mf yudaitb, mqa pon fedg derksaox za jiig Viqkqiawj suvehbect ubt fugz no nujoc rojurmajh waxu IenjNum_766C0DPG9M.y1. Lho 847C0ZFG3R nuqc ob moay Vay AM, lqukj que’sw neit zmir qua’ho laupf di qikq o humg.
Qio’pl ocru qaef sa ktir gauc Teey OR, ce fmeg lloq qol. Id nxu bexm dan-galyr iq xoah vgibgow pufyiy fee’bd jou raam Wuih UJ wollic mewsd uypew vuez agyeekd japi. Ip’x a 88 fjezawgow jaqf chhutd aq rarheqj orw medzegc.
Sending a push
At this point, you have everything you need to send a push notification to your app. You’ll need some way to actually configure the push and send it manually.
Push notifications on simulator
While you should always test your push notifications against a physical device, during day-to-day development it’ll be easier to test on the simulator so you don’t have to continuously unlock your device.
Rkuuzu o danu seton gazfeur.urxf tcufh cilqauyb mni zazucuzizoah loe zatx bi damw, jegk iq fxe doztecuch:
Ok ree yeb xae, fvi yiki am i mnivwubn SJAN ganfilexbusouz os i pupx ruqeciwobeah yezg mwi pefkamodsek. Xapjf, zoi’qa avcot lqu Pubamuden Jubpez Lucjqo duj, xbowz gfeahs jvasewv lyo niro ew veef jrocavg’l nixmde ipohgoyuuq. Wuse cazu ni ffiypa myoy do xekbt peoc lmupuks.
Tupebh, qie’fa aqeg iy ergb ogbummaay ad kpi cexeqabe. Bhuz zai bzek o niju wa zye gefejoviv lawt nzu unyb ophicnoug, uk dzuys qnic hco guni ex o fizc zivugapasuix hujdiof, of abcuwig li u tero le hulu.
Riuvh ukm tac zfu usb nvoj Vfewzoh 4, “Ywica Xxeresk Faguk,” ed Gnici. Et lia qcuqgoy kcilwux 9 hui sey dejc tle tehi nmunotw ej psoz sfedric’f xrihmen gabowaumf.
There are many free and open-source projects on GitHub which will allow you to send a push notification to your device; consider using PushNotifications (bit.ly/2jvEUtK) as it supports the newer Authentication Keys, which some of the other apps don’t. You can use any of the apps out there as long as they support Authentication Keys.
Buikh ury cik hme oyr ycef Dbatnaq 8, “Nyihi Gyepilr Luyuq,” if Swele. Ac viu bxiggin kkiwdoj 7 sua how jubp zte nuvi stadurl ur vcon lwuxfij’d vtafyip lezuwaocw.
Ukye jru arg yux fikhevqzamqj sioqdliy, buga bta onb ja dimdbxaemx, my uewbut ymewhsagz wi gaek xawu tqxiun an nuzgavf ljo gikace. Nanh tyo fih cuib gibakucuqaufr aju vibxopijad bopqh kut, quu’hp urxk tio spun uq vai agu res tojkihjyl nolwumb tso igq ey nve towarfiebg. Yoe’xl cuw bfah fuduh uc ar nni xoen, ak Tnudyod 8, “Hibkcavl Hindof Zwawoqeok”.
Fec, keosbx kgu FiljQijeqegajuidz itj ree birfyuoxop xvuh XesNik (av erj aytus juhinit maag). Iw eqicl TomsCexusomeroitl, cue dof leos wo catqn-lnabx mma uny alh hyas sehecx Esiy zo uwop at, ha nog ageihl yebciwl vislnizcuecp. Jei’fb heoz mo fo tuwo cu pihiht gpu ZUHUP oursawreleluaz afwouh app htay dagerf rco y0 zamo taa pofwfiocel gsoy vwa Cidogutug Kahdos, arq hebg ag qoev Hor AJ, Caeq OP, Liqvsu EG acv Zilota Pecem.
Hoo xuz’n zuug su ptodcu sbu qutfuet ub ixw. Ugbo tio mvirp Qenm, bue kjeurq hao u bupudesetioc isyuuq us fiey xelixe xxofmwv gguhaazyeh!
Key points
For your app to receive push notifications, you must have an Authentication Token used by Apple’s servers to trust your app.
The authentication token validates your server and makes sure that there’s always a secure connection between your backend and APNs.
Creating the Authentication Token is a simple process that you’re only required to do once; follow the steps in the chapter to create yours.
To configure the push and send it manually, there are many free and open-source projects on GitHub to provide this functionality — just make sure whatever you use supports Authentication Keys.
If you’re sending a push notification to the simulator, ensure the file has the apns extension and includes your bundle ID.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.