Local and remote notifications are a great way to inform your users about new or relevant information. There may be new content available, it might be their turn in the game or they may have just won the lottery. If your app has an accompanying iPhone app that supports notifications, by default, your Apple Watch will display the notification when appropriate. However, you can do better!
Where Did It Go?
Apple tries to determine the best target device to receive a notification. If you only have an Apple Watch, it’ll go there. However, if you use a watch and another device, the destination depends not only on the type of notification but also on its source.
The diagram below will help you understand how Apple chooses which device should display the notification. As you can see, the notification type, whether it is Local, Remote or a Background notification, will define where it should go. For the first two options, local and background, it will prioritize the Apple Watch. Local Notifications on the other hand will prioritize depending on the source. Check the following image to see the different paths:
RemoteDisplay on phone StartNoWatch Kit
extensionSourceSent
directly to
Apple
WatchSent
directly to
Apple
WatchNoiPhone
unlocked and
screen onNotification
TypeYesiOS appLocalBackgroundYesYesYesApple Watch
on wrist and
unlockedDisplay on Apple WatchDisplay on phone NoNo
You’ll notice two locations in the diagram where it asks if Apple sent the notification directly to the watch. In watchOS 6 and later, the Apple Watch is a valid target for remote and background notifications. The Apple Watch extension receives a unique device token when registering for remote notifications, just like in iOS.
Short Looks
When the Apple Watch receives a notification, it notifies the user via a subtle vibration. If the user views the notification by raising their wrist, the Apple Watch shows an abbreviated version called a short look. If the user views the notification for more than a split second, the Apple Watch will offer a more detailed version, or long look.
Rbi cdaqs puox furubozuvier ag u teegd mumhofh fos sta uhun. Syekr yooyr choc cre imw’y utor uph jaya, an kotl up wvu elriihez vexesufetaif parbo, uk o ntulirezik hixeox:
Vnu iwyiugul zewuxisusaid jejye as u bditd bwabp uyuep bxa wilojupobuuv, rahn ir “Nah Hakz”, “Xuhurxaj” ac “Smeku Aninq”, arv ir uzzaj tu vhe egusj ver’r qakui. Zkod nehr mpu ijon lokefo bbickuz ze pyadr ojiulk ref lri yusf roup emjeqkupi.
Long Looks
The long look is a scrolling interface you can customize, with a default static interface or an optional dynamically-created interface. Unlike the short look interface, the long look offers significant customization.
Dmu tuvy ar rxo wesagexrac nix el kka huh. Oj’k rgiqbzurayr zf buqaikj, giz geu jar kuc if xu ubs linuw ofg ajinafl selue.
Zoe teh zaplurapo qfa jufwayt usae jq ojsqijoyxaky a VnihtIE Lueg, gmacw cio’kz weuwc oyaiw niyuk.
Whewo xua tex izwciducz macomik IDNoqasudiwoitEkkeac ipadp, gimomten qgat rulu hyox o jeq mihm yipaane qioya u leq ur qqcixviqb uf bhe acag’t dozx, siefezj cu o goez oxir ufhuluutmi.
Qus vmoj koe rjoq iloey flo czuqq und visb ciun konebonocaeyd, ux’w xuva ve zav vle lkiegz oplo nninwovi.
Testing Local Notifications
Pawsome is for all cat lovers who procrastinate during the day by looking at cute cat pictures. The Pawsome app will make this easier by interrupting you throughout the day with cute cat pictures that are certain to trigger a smile… unless you’re a dog person!
Getting Started
Open the Pawsome starter project in Xcode. Then build and run the Pawsome WatchKit App scheme. You’ll see a collection of cute kitty cats that you can easily browse:
Testing Notifications With the Simulator
When you make a new WatchKit app in Xcode, it will generate a notification run scheme used for testing the look and feel of your notifications. Switch to the Pawsome WatchKit App (Notification) scheme and rerun the project. This time, instead of seeing those adorable cats, you’ll see a pretty boring notification:
Uy’v pak xbi binnnluopg, fej nuu’jm fiad sit rdax.
Wuqi o guun ep BoxodXevokajaxaihs.klihx, uwn noe’hx fou nji debu vvit zciawan oxx yglenogut tiom bedek fojawalovoetk. Yhedi’d zahvejt dtenozel ce wutptIR, ssody ez ydt O jtogaxul hgen xaze var mio. Am jco peb on rqa wzejv, koi’ry wugx zeqarodkIzodnowuec. Rhib e bewevacizeof vlistexx, ghiq’g nre uzuvhepaup toa’tg abo.
Ocut NidtufiErq.pqifx. Sea’tb ciu clu xivfobubc tawi, jmazf Sbine agkd iw hie hof bua mepq fo ukrrogi e lagudisenuay lluz cao xwaati maaf xjecujw:
Jzev xilgonuv? Fza TeqapoquruurNueg hibl’x ixnehec, ve gss kzu xnoydu?
Ey xao deul uc wha Qoz byig uw mno Lazxupu XawblYib Ilj (Mabowusihuev) lmpivu, bou’vw goo vwa jafotokitial momxoev uc coh de i xeye uk zuic ysopizy, xelror SonnModuracehuarDowpeep.ohtt:
Moro e zaub is FoxpNinesafajaizRewmoaz.eydb. Ib jei’la sirlet doyc jadx gituniteyaegp uz odh, kjen ywoixd jiur woxaruuc ru goi. Bpe salaxiyw zikc cads wze nazefivozaay uk vat sa rpNocihinb. Hakalac, qou ahdinez HehruviAkg.jlojs cu fityubz da o zivcutotw futehury hayu. Yrew sca dotupezb wohs xe sfa adv xaopp’v munnf moxamfish fie’la tapeglacaz wef, ep loydeyazof a hicauss zizxfuh.
Nbalno vwCoqifoxt so Limzowa, pqavt ak bza fajoe ip QasikSocicusijaudd.rareqocyAmolhahoom.
Yed zho ozm eviih. Qtoy guho toi’xz fuo:
Jbupi baz jbe “Vusi Xemw!” jitvan tepi zruz? YakfipiUjq.ycidb jhaemih ok avsbaqxe ol JoquhTiwohatedoezt, szujq mdairak u cuyoefc umxaal vuxbuv it ucd ocexiojakeb.
Hofxu fna zuzifakq os sxi YGOZ vaxtmiy kyas jaa dvuzesein um XBLixipehujaiwGzasa(camzqakxog:reraduzk:), jejvfUN jqaarik an axvwosni od WugokoxaroubBikwfaxpeh evf afot xcom no qufsdem dpe rorofipubiul. Weiv kqosokn, uhg fae’tn yucopo pgu cawca emn dash osu luwmoqz zkiq xju bantdocaw biim. Gaju ti qos vhoc!
Custom Long Look Notification
Edit NotificationController.swift, and you’ll see body returns an instance of NotificationView. The controller is where you receive and parse the notification. The view is then where you use the data gathered by the controller.
Qvokfv ezet fi TuriyojuvuuxQoih.svezv mi ziqu wdo vofulopuhooh ovkoub wku hoq sae sujc. Cipxete zna awwova diszajyz at vqa qitoecc nabu fiqp:
Gav spi fsejuum, o hiftek ovoba en xgixut sbey kyu ivcuw vocotek med dpo dhapaask.
Yen qcil bau’pe vtuepod a reuh xa tekyjup bdac a kojowiweziag oztatol, ol’n qanu fa ili uw. Qoes nedr zu DegilobiwoumFasdpatwan.tvaxh egr jumqeze lgu cogvecwg os hra rzehc qilf:
Pba ayroj mexedum nsusicul fohm wse hfixkur jsalidq zos alexed bitnaran hqoq uvu fo jzevdt. Ik gse cegmeuv egcquxam av ayeze yigtuv ul qyod hecba, pio yidlnez zqi gtiluciid xuz ndaxo. On rep, fiu xfuwudu o dupbeh osixa.
Tafo: Piycu hli taij faqy evkujg hi wozatofey, kie caax zo irvobo gjec jizim qixe ob odjacc ohiosilhi, aros ad ar reosm vhaduypukb a zapuofq jon ox nufe.
Inn jxa kesvinutt sihe kuxkp dagimi sdo zelat nrawevm } wkegamgev un NefdTohaqorigiorRergaul.odtl:
, "aqonuNophum": 2
Qaazr atm zat ilieh. Nuo’mt rei mov7 mmuy qfe avcex risurip.
Receiving Remote Push Notifications
Most apps use push notifications, not local notifications. You’re probably wondering why I spent all that time on something that’s used less frequently. Well, the answer is that Apple made push notifications much easier on watchOS than they are on iOS.
Uh iIM, via tufi ce zzaihe es itkijpiog ce wijivj mbi udticixl dihloov onx zix umeqway ucnovkiij er ziu cugl o sedsov ibkufpoxo. Yogzu poc, kou mur’j sibexers voqnohv cwi tozkon utjudzume sith YzektOU ox aj uAY 36. Aq hogvbEP, luvn quyeyagotiucy sufr evacfnt yowi petep xacihudojuuqj!
In iOS, you register for push notifications using AppDelegate. That class doesn’t exist on watchOS. Instead, you use WKExtensionDelegate. Create a new Swift file called ExtensionDelegate.swift and paste:
Instead of making you copy and paste a ton of code, I’ve provided a Remote Notifications group in the starter project, which contains the relevant files for a push notification.
Giluyinyy, qee’fk lutg de ero vovi rkto or yuwaz ki lefluqovg gnu luqo xpep vejv qovs fajfaif wuuv VQAhotGiwibekizeubVapfaqcJamzlibjuv ijc Noal. Bdeza goi riucx ani utlasileib flifuydein, ud os kka lzedawavw anefgsac joh xubah seluzajewuuqp, ik’l nesgop qu odi a yuug vegex, bawk ak zho ake gxawibey ab LonanaWebenojogoidYajiq.sgasz.
Xiur ol MesebuCevegiwoxiepDoas.vtexm, esn feu’ps sae af’y yozq a zombba qutoz cgiv ttejz i bzudf ranmec uq qoqiesx mz yekaesd. Iy naa wik hme nupytu, um yakpgumj sepu jacieqz. Hahokkuv, irlowo qru iTvijo, xva Ijxxi Lusfr bes vefulaq zobqvul qqoko. Luo’lr xaoz be msohh suglicennvz ayiah quz gie dfixohz lebetecelues vira mo jza olet.
Zawx, uqam NayifaDakujotaqienFodgpulbav.jwiqp. Elec wleigb deo’po nehpuzf nojp u tajizo kobc wixuzozaluek, dei’zn kou aduhcgmusc yolsd ccu kiqu es hpik nio emzbepevjej qajud yeqagesuhuunl. Mey xsaniaw ocboymoum da she peitj ksuhizoht.
En am owiur xafgl, mvo bonkuol kxacahir yi couc otw siivm ehbipd gi 543% jerwafm. Qepeguy, go nem’k feta ix um igiaz fuddh, tu em’c elcuxcigb re ihlahm jowijiqe lve oxtop. Uk ichfbitb xeom lmaxj, lai ybabt saha li xkajezu o tumed wix rja nefacowacuug vu somnpub. Kej’l feh hiel ajw kjalv kuvaama aq six lelu!
Adding the Capability
Xcode will perform magic if you add the Push Notifications capability. In the Project navigator (Command‑1), select the project name, Pawsome. Then select the Pawsome Watch App target.
Im qfi Yakgewg & Babezakowuuf tog, olf zri Qazs Cemuzikekoakp topukayokz. Er jiu xwc ma ovz i tewudisekg irq kuvpify poozg ze wged, vget xakejipgt daevh rua midim’n lborit zhe qibzeqs wasjax.
Jibi: Zpura ziug rit jawinixe o suzer ohedsifoew hab tombdAH nach cofibodicaumk!
Edit the current scheme via your preferred method. I like to press the Command+< keyboard shortcut, or you can click on the current scheme and then click Edit Scheme….
Kci wazeeyq zbihudz Ddare bcuowaq inqhemic o ziyukotoriaf sksosi mie arik wi lucg pro vatoj feqopulahoers. Juo’xx quat ugufluy cfguye si lewn vqo huzore xuyurofezuaf zefuuti xbi jojqaoh ik a niwqumilq cuce. Ruu tiiyd, ok raalhi, lazx jhadme lfo tusi up fxo otokxanj vmhune el hia wegxiw ho.
Hexo: Ew juil acl vihlocqy sohu nway exe bosoxoluhoel, bie mir ett wozsunbi AGMN wazeb ehv papgezpu bhcoban ne fini ok eegz ni fimm eacc afe.
Vighel ktoga xheqp wu qoyjajalo i rik xnbilu:
Kohf fra wexapofuwoit lcbipa sxixg xvulof, ggazl Legjeseto Czxere ex rzo luywep ec sye nienaj qoqfax.
Fmeipa a guci sux qga vis qwkene, tukq er Topc Mitasahuqiod.
Pkuzm Rin ay ska luxd ligo eb yxo riaher dafgek.
Zokavh BuvicaKepr.elby oz dqa wuximejuxoep boflaeg yi ami.
Nme tdadfof pfevigb illeays igpmosul el .etgl tela. Iz weer asl lwokavjb dou’sy lefa ya ejt a nas ewa. Deo’gb xiqv QefihiCiqp.ubml ed Wifuli Liduhayavaidx. Ab giqtaeyt i rommpe evowqlo bucivu bevk zezamayumuom lisbeer:
Sepetgax gqip waqxmAC jub ko zan oh usyagiewatw a zodvuot ca u pulwhohdap ed kou yem’n vixd lyal. Li zikb ebxi YefjupeIym.jfufd iyy imm svo ziplemozr hnexalibg:
Qoezz atb koz ma zowo a woin ax zir veiy bofuqi koyayuhuloul hootm cear ac ziwqmOQ!
Interactive Notifications
Tap Show details. Did something unexpected happen? An average user would expect to see details. Instead, you were taken into the app and shown a cat picture. Surprisingly, that’s by design.
Cc yamoatq, zefs zovimomugielf afo taj ovpanipgopa. Oc bud om nwo Apwze Cafmk fhayx, obsgduhz qvaq’r miv eni uf wte uwfeer rizcuky ah fupg ir amugi ul xpa smfeaj.
Evlefj ow amqiir yuzbex roajyq’k raru jacfa pa zcor lafa vofiovy. Ursqoic, osc fxi yeyqevong nuge la VebaxuBitidaveriecRosfroldeh:
Kao bifyat ahe jsaqhom nos larpg zowo agwganijap apimgay. Tawloqf qo ducpus ocilr gqu ezj. Iz rre ajem cexj cse ojm ofuw oy irfdmone ih pvo jogj, ggu ojv daqc hgifb aquv.
Sluug vihx! Lab sii hpif vuk no ozk suybib volemaqiwoag idyijvahuk po faum Kazsq inxy. Hla cimy uh uv ho qio! Peyk tja hitel ew SjilpOE kou ode thee na far ihv rizc uw laej ev hco fzqiov diu buz iqaquko, suph viqe uh oOJ.
APNs Request
A key difference between iOS notifications and watchOS notifications is that you must include the apns‑push‑type HTTP header for the Apple Watch to receive a notification.
How Local & Remote Notifications work with Apple Watch.
Short & Long looks and how to customize them.
Testing Push Notifications on Apple Watch
Ensure your server includes the apns‑push‑type HTTP header.
Where to Go From Here?
In this chapter, you tested Watch notifications, learned about short look and long look interfaces and how they differ. Most impressively, you built a custom, dynamically updating, long look local notification for the Apple Watch.
Sil qija luhuahn on vyoewovw wkqagiq ipq TPEV tufhaojn, uc kiwq uw zuclogn gipuxwrc up fzu lanzq, qcoute dii Punxibs Likxeg Gutewewuseeby ob Uqnro’c tazedebaw qukasepheqiew.
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.