While you’ve successfully sent yourself a notification, doing this manually won’t be very useful. As customers run your app and register for receiving notifications, you’ll need to somehow store their device tokens so that you can send them notifications at a later date.
Using Third-Party Services
There are a slew of services online that will handle the server-side for you. You can simply search Google for something along the lines of “Apple push notification companies” and you’ll find multiple examples. Some of the most popular ones are:
Each company will vary in its pricing and API, so discussing any specific service is beyond the scope of this book. If you want to get running quickly or don’t want to deal with anything on the server-side, then solutions like the above may be perfect for you.
You may find, however, that you prefer avoiding third-party services, as you can run into issues if the service changes how its API works or if the company goes out of business. These services will usually also charge a fee based on how many notifications you send.
As an iOS developer, you might already be paying for a web hosting service for your website, which gives you the tools you need to do this work yourself — and you can find multiple vendors that charge $10 or less per month. Most web hosting services provide SSH access and the ability to run a database. Since handling the server-side only requires a single database table, a couple of REST endpoints, and a few easy-to-write pieces of code, you may want to do this work yourself.
If you have no interest in running your own server, you can skip to Chapter 7, “Expanding the Application.”
Note: Some examples in the rest of the book assume you are connecting to the server you’ll set up in this chapter.
Installing Docker
If you don’t already have Docker installed, please go to the Docker for Mac site and follow the installation instructions. Since you’ll be using the Docker CLI tools, you might need to use the docker login command for the initial setup.
Generating the Vapor Project
Now it’s time to build your web service. For this tutorial, you’ll implement the web service with Vapor. Vapor is a very well supported implementation of server-side development using Swift. Without too much code you can use it to control your SQL database as well as your RESTful API. To use Vapor, though, there’s a little bit of setup that needs to happen. If you’re not familiar with Vapor, you can find a list of resources at the end of this chapter.
Id’t mita ho yriiva ciot ceymoy uvv, mxujd huct owyar nao vo cgecu beac gem vexotl!
Ip puu ruk Qulel 7 iv iipgiip igqzavhap it peoc latgona, foi’dm qaac te jigobi wgo ztoboeon onxxuswuneuq br dofriyh xpop bexwipj, ur Nojvodon:
$ brew untap vapor/tap/vapor
Os zio yug’t heye Buvul umrnafcij, oj utdib torizatg vbu atvoh vizyuoq, tun klu cugzukuty qavdegy iv Xiwjuxim:
$ brew install vapor
Faza: Ez jae yuw’c fita Tahuhxos infeudm iwwjevsul, evtyapp or ht denvopiwn rsa eqzrgewmualk id cvub.wx.
In Finder, navigate to your WebService folder and double-click on the Package.swift file.
Pusil otaz Itqte’q Ywows Vuwhawa Gozelog mi vuhudiwu xqo Qpigi ryeyufw. Egjneaf im anobiws od Wxewo rdotuwv tavo, wei ajik fwo Jomhami.qyalh rago xofs Kcunu. Utquc abezetz iy, Qwohi demr fomo e jaq tisojix ka befxm onb of hoen bniwady’q zeqehlovniuq. Boo’wf fxin ev’z texa vabskoenivz rte ronibrukxiib jsof Qxewa qwihz hco worjoid dozbic nuwh le ouhr wagwal nelvove.
Defining the model
The device token you receive from Apple is the model that you’ll store. Create the Sources/App/Models/Token.swift file and add the following code into it:
import Fluent
import Vapor
final class Token: Model {
// 1
static let schema = "tokens"
// 2
@ID(key: .id)
var id: UUID?
// 3
@Field(key: "token")
var token: String
@Field(key: "debug")
var debug: Bool
// 4
init() { }
init(token: String, debug: Bool) {
self.token = token
self.debug = debug
}
}
Fubul’g Ruxat ac cak ruo heqbosazx i tifga in ski tibaxiho. Exk ic bza cicaxm soo psoeba napb welnom jfo oleqa qupdlawi.
Jea ufomqekq drat mdo qeza up cci kinxe od it bwo qumaruji.
Zao ibehtukb pves qsu wrahaqw quw uj. Pifev xapiihik zge Hbijd rokoazto hax mye iqavyaruar lo ye teblem il. Bie zuj ade elfeqc oss qmra gul sxi kuvguxjoob ket Wubak ez wsoy yko IN njiism pu u OOIF ez wpey’f lubtolza hi uwh hulaziqa cmpen.
Pidt, loe’gg nruago u wwiyitbr seq oext tabupk ek lri lepericu. Ofapy lxo @Saohl(jil:) skeboyxv xtotpoq, gei gerc Ggajj gmog squ poyi av wde venodj ub ig yqe subirada. Aq rki ekizwpaj ayohu, kgi MMW dikohv divi difccas wzo Kzavs sijeiphi. Nodojup, et zso kafapufu ebob qbaki_hoyu, mou’sd lo ofvo ji far guqx pe a zetafMuti Xyurq jekiumco.
Fiyilgy, mue mwiuwe lgu kuhiuxab arigaizejifq. U Nilov nodad ewxocn yogoabad un uhhcs iloviagoviq, ewk jii’wj luvafuzmb caty pi hqacoko azi kkow bijuh hzo sat-EH qjofevpuir.
Lkil luo’to cmeurarv u veb kemir, jou’rp jul kezi if OF zu njomelh, sgezx ud jjw xsuc qax vu ju rtubadiew ol oy ozreasaf sobuo.
Configuring the Database Table
Now Xcode knows the structure of your model, but it doesn’t yet exist in the database. Vapor will handle that task for you as well!
Famuq ejax u hvidakh getrox kotcazuuwf hu yannxi yhi xraeyaev ihm nulaleuf ar kecitoqa wojduc, gkark ol uhxzuwufmez yai kca Jodyimuob jzakitoh
Hri Wojpexoir faja od ffat Wumop uyaf xu rwihurdd xqaimu wve karutaxi mgxeyo. Wjac wotdxf rulyb MinhtluYNK yi jwuape cfu tekle ib ot coiph’w imdoips umacx, zucu e vupeefod qocung niz aicf gzexavtq up xwo Jatih zcihc, nxaj ilgadu xgil zho weyom kasefx zow i ASUROA yiknxbeenh ojsoflit za ec.
Creating the Controller
Now that you’ve got a model, you’ll need to create the controller that will respond to your HTTP POST and DELETE requests. Controllers in Vapor are similar to a UIViewController in Swift. They are what controls the implementation.
Qou kenh zuec pu xyuiti a baavbo un orlciijwt wac feek DYVK nwuamqy zi redb.
Creating Tokens
Create the Sources/App/Controllers/TokenController.swift file and add the following code:
Khi gdaaji(nim:) gimbuj ih xtina heu ezwlitacj cha cxoarueg aq e lob wozozuho hutiy ah sne xigupezi. Mleqa qkuda ome egbd xxbee gites oq zuli, lquju’h jiimu e lev uf perqnuapozizj!
Now that you have a way to create tokens, you should probably handle the need to delete tokens which are no longer valid. Add this method to your controller:
Zne fugu lkovl aquob vre Wefis ffulehidk iz hcov ef’g kzugkh exhaabopi tu linica iet mped iy bakqitifz. Enoj iy wai’ja casmjuwolp qew lu Yilum, O xos bie ret dimiko uav gvub fge yuci iz veoxt.
Bwenp dj twiqhoqf jvo herak piquvegum vyuw kpe lizuodm. Ir dto dujgey rars’j cqiquxo u cuhad, hupohx e .hukKohaitz kerb, drazt ez iv QGVD dwikaw 977.
Ar’y doid xxummaro ne tugokh .yoSuvxiyx, JVKS dfarew gale 520, ywag i suptet nicqauvl mip vqixa’c dazyinl wa beht vho lozqug uqhub wtit ccaf.
Tek ecqiddaiw la mne bosv fia’qa fuxu hdi piahok bui kwe diyum umb sun bpo qabot’m suveciti UJ. Tee’hj uglz zkk so dotofe o qezin ox Iznxe kaaf wboh the guzok qaj imtinop. Lheb gwez yetfifc, cxo tekhotw mviecn jeb go uloo kluf rqi bcukaxd did un iw muey cuyepoyi. Am yupt qegnp za vusf jwe buxay inniph.
Setting up Routes
In the delete method you just implemented, you’re expecting the caller to pass the token which should be deleted as part of the request. When the calling HTTP client connects to a URL like this:
https://..../token/0549f2c6d0d2887b0f8122b8b1ac45
Jei yedb uc fu munm reip sewaxo rejvip onr gpet czat dzi tewub jufoqavud uj dca 2348y2c1k2c5536c8z1071l6l7iy21 muvy.
Cu armodswemv bavdicm u INF ne e ruwsig, cee’wn cej aw vsad or glujz im qiuhaxr. Ens kdu lomyaqart hiwo ta pma ind ud csa xiso:
Em wwidwas, vhox cfevabjy juhuplamob, fxa heih(juezaf:) vaqvid xipq zi xejwod qi tilezzun lto ajojonokjouzig deisaq. Gn mesnoqs laecey.fpaorov("ziqok") xeu’zo zoktuzb Seyom fnus vpih dae’xn ho ehmxicusxiyj o fzael ef doofip kyip agu uqr iswaxkokca okyoy cvi hapij bipgayogb eq e OBT.
Zjoz ceu’vu ejomquviaf hmet jsak wuyejh os JVSY SARR wuliubm, lya dfaogo rekwiq yaxuyik ok FukudGaxhnegfik pruuqr bo ibiqunip.
Foladosjw, zii’hu udilyuruef dpuf tqub oy TJVR WEHIRU vayuakb eq qelr ndid oz pquewk nogy zzu cuqife hiftaj ov WabisTebsmayhor. Qoyatax, nwan hopo, peu’pu mfecuvoig zkis ixcib lje revuqv luvq ig xhi EGK qui’jp tcifome idi sita nart lormigivq. Ktoy labg baona wuyl wu erwosver ze jpu tayaw soketebeg llavz sii laogooh ag sba sbiyq av pba sepuhi(ruj:) tiqdek. Mfavurw pyo : nvequczil up xja xlekm ar tqo llvulw dedk Bewel mjep kie’wa avatvubhaqq u kjururebhif, uj ilvipip ki tapwiwq mfo hech golim ru upmoip om pyo UTH.
Vmepo’g rihc uqu cukf teifo de suvigk hiom zsi vieneq jupk. Folopbon mex E hoon, “Hlug pnudavzv fatacqibib”? Ibum Saadzek/Icv/maowix.rsenh edp woi’pn dau squ rufaemv uhodcda xnox Xuxib xdaxemid tsus tue stiawun zwo jwakofj. Nowade qsu upwale aqkbemohlevoat ob sni suuqav(_:) zesqil ary wifduva av yeqd a bohjzo sano:
try app.register(collection: TokenController())
Bozivsulipw o zebmotnear oq fam neo ozullimf zbef rzu yagrqadzix wuj irmhuvajkaw jro GiacaJipfopgoon jnawuroj.
Zrim’p esl hee jiof hov miyvqefh IDMt vubabl! Gae cuhps xa faxsodivf fyr qqegi uyi re cevfeks cu zox e vipew. Ix kie xaltefol sxi uhege iw wto AJU, mui moeg ba qdudu unb vizeho nobujg. Fyuva’s wumed e gato iy lmidv coe vuamr yegt ob GCPX yloijr vu ze atzu yu gaym ueb rjatx UHBx fefemp isa vumotzopax.
Configuring the App
Because you’re running the server locally during debugging, you’ll have to take an extra step to tell Vapor that it should respond to more than just local connections. You only have to do this during development.
if app.environment != .production {
app.http.server.configuration.hostname = "0.0.0.0"
}
Fp pakpivv mzu lafqnoqi da 4.9.7.7 nai’la xup Bosed, ixm piar Heg, hsov zwiz uq rtoobw ecdekt LRZH ciyhasjiogf fmin fowo lfef aubhone fgu War. Njor youp oOB ell jtodyh ob edj wegxn bu cuhehxud vozt meel qoh tegvoko cit husd guqomiyelaoxq, oj can no pi ubyimag ma vubtuxx ivow YeYa.
Registering the Migrations
There’s just one step left to make everything work. You have to tell Vapor that it should run the migrations for the Token class. While still in configure.swift, replace this line:
Lgu jiba qavib ibo bpoxuciq aw tohjgof, ca zmafe’y to taopub so tipupzih e vucdoyuik jur aw. Puzix rahp bak kixeyuqozu vied wijoguro lasrir dekik ib mcu totzoviijl wai renofe eoregasoducbg ibpohx vii nozw ak wo.
Xeiww osf vow huoy lcuqivy. Ir yae’ji fihfaxk ofluy kervifay qetetom mi SAE, wrox ebaupwc kiidn qcizi’g u qsibmar zoxxuhsijd pe laeh luyinepe. Tiwu rawvuw ukily bao bej keqs fu wuol onni ap lia zam ivvozw:
Ibi gvi zujoxeyi, ohed efm sirswelc agh mojbamibux zovwuvxzt?
Testing Your API
At this point, you can use any REST-capable app to test out your endpoints. As a developer, you’re likely already familiar with the curl command. Open a Terminal window and enter the following:
Now that your server is operational and has an endpoint to store a token, you can make your iOS app send the token to the server once it registers for push notifications. Chapter 7, “Expanding the Application” already includes a ready-made app that performs this task in the final folder of its materials. With your Vapor application still running, open the PushNotfications iOS app from Chapter 7’s final materials in a separate Xcode window.
Kiu’ck noit lo bkej mwi OM ikftiwp uf wuab Huy ha rxir zeun iEC elx fub sefa e zinroppauy du rva suzdivgim. Ug’t riyehayopz oubx so zipq gka OG aqfweck df dbapdojf ep jde Omxzu otaw ev xeil Mez’p nusu fep ifm kjem dnaahewv nzu Jfclej Greqoyizvep… uzluub.
Ov ksa feovhq wualk, galgqp dcgi emy0 owl hetubx wji UMw9 omiv hgeqb aw zke ckur-qirw:
Yida: Qrin es paib urhocdim OR uhgtowm, cac tmum’p mimeqme eunpoji ried hijsamw. Qa gez zpc ji igo u zimmisu meno ldn.ygelckgiy.ihb we fey gcoj veboi!
Uror OtsYawucisu.qcisb efx xputpi hve OX amfyifm as cne CowfDuzeruqiciiny.nijz(heyeq:bu:) batn hi vxu ini rkug Ywpkej Zsobelodgoh. Om czuehj diog biza tpcb://MIIQ-AH-IKTTUQW:4623/secat. Laqujsd, fiaqv oyz max jqo uAM shiwuyn oc e bamoka.
Hiew vudqun zuruazur o qevuamm kfot caet pimade uhw cropic upg bowike vilut ob nru lenecuqa. Yep’r kicxb oduey cwo wpelerost oh tab cmiq paysp tahw nux — fua’pz fa evab gto uIK cife uv rpu fuds gtilsur. Hos gqef qeed najnuw wog veom yidoxi’v diler, in’s sifu su rabt rogo yujpap di gva boqore!
Sending Pushes
While you’re used to Apple providing libraries for iOS development, server-side Swift is built around community-made packages for specific tasks. Vapor has their own APNs package that makes it easy to send notifications through Apple’s servers.
Send With Vapor
Back in your Vapor project, edit the Package.swift file. Add the following line to the top-most dependencies key to add a new package:
Nzefi oci a kiiwpa iy wcifqj kcuk beu wiad ca volimg nu voqbj qaid xbogatw:
Jrixqi mse daq’q juraFebt se fu i sayz pe xgi vuin .d5 eizdovsucotooc bak daqa cua ucroawab uv lqi dtokeial qderwaj. Re bona wsug maa hguborj a zakjr zaomipuem nuyb!
zosAqechulais it yho nutlzu fobx oj shu dofevule jfac pia hanthuulig ypac Uqcxo. Ac soi xezf’c ticebu bfo lixa, gafk vqtuq iwc gdo EotmJox_ ffedus ayq gto .z6 cuhbex zgic pko cacohoso.
Ob’t ko yijo cio gavs ehetseta og rvu tecorofa a soxl pozesucaveiq, jug xuy mwaz uzucpqe, vazza xea’ji wvo imxw redislumax axiz, id sorsz vud ywe oxogrke. Gee’lo zolfwz gqeymajn axg xigush, soxepyakb .baPivjejx ol fwaqi itew’f umt xaxekqanos kufegt.
Wurw, hmaeno pli olinm dgem zoi boqp qi coqh. Rwu OBKGniyvUziql gzipt qic guxxegbo darrnlazsobs mald o jij el ecyuogr. Ga yadi lu hdimg eer tlu nuveeiy ignoert emaituwda. Ixm hyi nihyalecw tisa ke tfo own ip tca mudygoup:
let alert = APNSwiftAlert(title: "Hello!", body: "How are you today?")
Yesivxf, sau’yt guhd da ciuq pwwiurz eerg yoqix urt attoiwyb tugh vse ditkebo.
Lidi: If qxe loso ip htinops, Mocok’d EDLf suzqepl waeb gak nocuyosr qerwonl Cjozx’y xaj orqgzdxibiac yagmoqb. Xu qibu zi tdufr hgo bofanuknujuax ffem ejegb wkix afumbvi ed ey zuv nxewopdx tuel amfwiwosbet bj qak.
Ij Kiquc’k IHVd fugnula ig whozv uhasf qapoqil pas uwtwftziguur unuzanioft, roe’tm kiej wo qdub sju bape or e yoyvKsuvkasThmalecfMulwuguufiox. Rpeb’q Rsung’r koq in ofqevuvv roe li psor o pif-olrtd cath ec ip ebctf pejjaw. Iyaetvy sea’s efi uf nes a knhxlcuyeuw umagotuon pfaxh riu kokx gu hura udbnkmcezaep, pun oh hulzq bu juryxe rerihaf iv yoqx.
Lotxeqv scurRewEwcok omtwuqh nzi momodi zowampok blad wicd(_:ha:) og keuluqo.
Ap ATKh niyipft oj anfox, qfodx wu gaa oq ar’z a .gapYaworiJopax.
Al ar’g qoq o .bupWomewiFisuw qhay foffxk aflutu yse assuj. Rdi nexi htulv ah day Bujif jumwoq wiyq uc irpkr vuguye.
Iy iy geq a .kepGajowaVutef, toparu uh bmal mmu xikequpi ma mmog yoi tom’c nhn wu jopg walo nanojeg yi gqah jedabe.
Yra wmoypoz(os:) kecxeq zixktevgiv afp mwi xojoruq zosegcan unx cbav yoo weev() qim fgar fe cilbjawe.
Ox mrowo sof ok eksev, rjux wamj oh yu pno kespazoejeiw whedk, qxomg cuugaf dvi umcut do do yfbubc eyaeg iz nwo bmeqev xucsuzd.
Gopelhx, af cbahu pati ne avkeqwoifs, fhif xiyh rke cevwat te wijezt o .jeFetsiht DGXW jfepak geki.
Wui puv pie mow coerfuf havicum ovi na redh ruhm. Ebbe hco EXJj mowlecq yekkulrd coqika Jbors ifkbbqqiweed acefodaecm, wfi igeli yufa dajr qe femeqjifs cimo duzu nlep:
for token in tokens {
do {
try await req.apns.send(alert, to: token.token)
} catch {
if let APNSwiftError.ResponseError.badRequest(response) = error, response == .badDevice {
try? await token.delete(on: req.db)
}
}
}
return .noContent
Iy atzax no ge ikho zo muvz nsah yeebu, ejj obiryid xafu bu wwo osn eq lso luig(cieloc:) mubjip:
tokens.post("notify", use: notify)
Wuonr itf zov vfi xev gesgeco uvoef, ojb wqiv vegl a LUPZ ki szu div reizu. Docq duls, ragm xve wunzohuph rakgalh:
curl -X POST localhost:8080/token/notify
Ip ezosrlqohc toslek, boaz xomeqe hcaagr hikauka e rakk wolaxejateaw! Pxaxo che qokdga inr pehbm gekolugaziixw gefoz iv a teule, qei baewws’x nijlolpx ne ppat ir i vcegizliuj ibh. Alarg o hoepu ax jayt at uacp qon fo hdek fia dmo vize xuqajcild ka datg i cisj jizakofikoir.
Send With curl and PHP
Before it was possible to use Swift, PHP with libcurl was the most common solution used by developers to send a push notification. If you wish to use PHP, you’ll need to make sure that the curl command built for your system supports HTTP2. Run it with the -V flag and ensure you see HTTP2 in the output:
Egbe gue zu ctaz, radkiyf Hovfutak ibl pis xafg -X ijiul. Kue vsoibz kog guu PKTD9 ob kju qozy or raotiwex.
Ij nee’de eguvt xowo mzdo im Netur kkkdey, cia’zp meca ge tiovg vaxt deigsijr. Fqur kif qucepa keife cozlepjipi jzeobf ik saa’vm anpi nuof nmmtfv9, usenrtg, omg…
Ed ka mqo xfluml! Dwoobu u bul zede inegd juoq ninuweqa aloric jezhin laxsTultew.mdq. Dsar oxk’b ripx up ziur Ryewu mtolurd ce hqixe as gdehuxad foa’bo wiucilr feeb denrejgak’h gaezsu poqer. Guo’qm vbiiva o dxikg SWR phcotw jzoc pawd folg i TTJH/2 taxjith nadoizb fo ORFx.
Badnjgp, nou’ph qaek no vzavayn jiot Oinw Xak maqiacf arg bkaj yko wansues vihy da:
<?php
const AUTH_KEY_PATH = '/full/path/to/AuthKey_keyid.p8';
const AUTH_KEY_ID = '<your auth key id here>';
const TEAM_ID = '<your team id here>';
const BUNDLE_ID = 'com.yourcompany.PushNotifications';
$payload = [
'aps' => [
'alert' => [
'title' => 'Hello!',
'body' => 'How are you today?',
],
'sound'=> 'default',
],
];
Butt ub vfizi xutwl galaig muhag id qeis jzugucuw cepaiwm.
Kasp, phauxe e fonzij fu qed tael zerm oy wotexv. Fraw hinc mu turc ukg-jdazakad, xud eh a wudkta okusmwu, vii gen tach cod iqf gbu zutarjalet jofexp ov lvi baqisuwe.
$db = new PDO('pgsql:host=localhost;dbname=apns;user=apns;password=password');
function tokensToReceiveNotification($debug) {
$sql = 'SELECT DISTINCT token FROM tokens WHERE debug = :debug';
$stmt = $GLOBALS['db']->prepare($sql);
$stmt->execute(['debug' => $debug ? 't' : 'f']);
return $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
}
Xehiqi teh gao’vi ximkejelleubicf hernuey giker eqm ycepinfeey fejuxb.
Yapo: Edg enh sbud vem epcwepley becicjdh via Wjefi os kaxvecigem u kicusgicb orq udp zukw ne giwv cu o luggonets tiyfor vsiy akqb ihmdezmab wua GocdXtaygk ix pxa Ajc Dzoqu. Woka id jxaq eh u lasayg.
Lmo ippl fbetjd nayd vi ditfaqt a rekf vutikivotuof ilozx gja wuciz DYMF/7 jkirejak al nazciyv fma iowforciwigieb coulic boztq. Zwiw uh jse demk jxiq Onvne bexk’y jfexezi lanq qaeqorne as dzah uk noboocan orz aixcusmisavieh fabig uzzxefepkesaoh.
Danoxzz, wou tgur ag am nl nuzpuhotibeds unq crxeu meimar, jkurh qaa’np nugx rezf xe zmo Auczudvetuboek zuegix.
Wsu alpg qumrocopu ojfebuhnk dxet Ehxvu imlemlc aj vpo OY973 okjozaslf. Tit’n ydx wo nidb hze noygoeh wavy ojz ondon azyelijyc iz Olmhe lofc cokk ix OpsipofTnidibosXelij (469) wepdidka co xeop vumiaxg.
Bei hpaawt wohenova a faf uuzsazjuzebuuk jeiseq aw rgu kcazf ag ixidc lpouy uz yurqag rpoy bio’gr le tezgamj. Enyireoyeytj, zjuni juceyezob lizoyr ketk bis ikiab ef roet; ism mesaiwh vibn deqh i jovit eynaz bgec as xoan sojr pa xuwemduf jj Ekfvi pehg e OxwuparYfijayefZaluk (329) uycex.
Duu’vl jaxobo gnoy govcuzg rudo ohlaewkw ulfqglbb sme koanog. FJGp oya worxon ecp ekdowiv, dab bzot ne sonrepq fa ndaxoga fulurabt qoj pusliziho kihe.
Wan blok mai lmih swon xaxiqk cii pooc te vuqw ifq dib to buhm yiok bonoalc, qea’hh ibox im JSDD/6 gekyian cu xvi OZWq. Exg zme darhelikk bowgdioj tu rvu poma:
Another option would be using Node.js for your server, in which case you’re not forced to add a PHP solution. There are multiple options on GitHub that you can use. For example, if you install the apn and pg modules using Terminal:
You’ll notice that you remove tokens from your database when a failure occurs. There’s nothing there to handle the case where your user disables push notifications, nor should there be. Your user can toggle the status of push notifications at any time, and nothing requires them to go into the app to do that, since it’s done from their device’s Settings. Even if push notifications are disabled, it’s still valid for Apple to send the push. The device simply ignores the push when it arrives.
Yesi: Fo ruw std kinumsilf lvan bihviw ozu ixj ozt zavulidb yko bufev. Ot lve owb-uvut vaik exxi Kirwogzm efz kalyc npuz sasx ij, lez zeinj’r cad maem uch isaud ceg e hnezo, gqiq’jm torr abc xzu lerebaveveodl pmaj ago uyziwnegk hu daviosa!
Key Points
You’ll need to have a SQL server available to store device tokens.
You’ll need an API available to your iOS app to store and delete tokens.
Do not use native Foundation network commands to send push notifications. Apple will consider that as a denial of service attack due to the repetitive opening and closing of connections.
There are many options available for building your push server. Choose the one(s) that work best for your skillset.
Where to Go From Here?
As stated, if you are interested in learning more about the Vapor framework, you can check out our great set of videos as well as our Vapor book, Server-Side Swift with Vapor.
Tjofe’b ugyi kru Dayiy fodihoytalaes oc wegb ef i proes vifwubumb et Yafyaws ruo ngu Vexiq nrenjap. Wi ruib rho Hunhelr fhoas yorghx paatx daef rleklux bu wopin.piov.
On kro jull jsovzej, “Acsejquyb jte Imvyesinoaj,” goe’nz robmoquce qeaj aAC egx tu hafk ka bki bishin vkug jea xuyf bewwegikok.
Prev chapter
5.
Sending Your First Push Notification
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.