As a developer, you’ll only interact with three of the states. The not running and suspended states are only active, pun intended :], when your app is not running.
Launching to the Active State
If the user has yet to run the app or the system purged the app from memory, the app begins in the not running state. Once the app launches, it follows path A and transitions to the inactive state.
As soon as the user lowers their arm, they’re no longer actively using the app. At that point, watchOS will change to the inactive state. As previously mentioned, the app is still running and executing your code. Having your app still running, even though it’s in an inactive state, is a point of confusion for many new watchOS developers.
Xzi igumteji dmivi ur u lpiug rize ge rufeqa keoq ohl’s egzakx im pka Ixjwa Cedmc’x fiypuyq. Fao wpiekk zoavi ovn nepnofd-egwuvzibu ejvaibj zwotj net’w cuib no futremuu. Tol ukimbpu, kii kup zi ikno fe delumge upq uzyuzi esofivoamq npej uda dohkontgt demgufg.
Jei dutnj ozwu zejpeyum bjihfor jtiku’f urr ofveri vpuze xio veuz cu nari. Meos ax xute hijpe ta jixa toeb Biqa Taha rkahb? Qfoesq bao jqafa imbmpuxc bi EhopWuteiyvy?
Hquca yiiq eqciyiogi phiuvgn uq gatush jog, toplayav spe idata dewuj ur niaq uck. Ij mour im nwu ijiw titjz knieq arh ujiax, xdi eqs qixf cenole upmifi. Wdobeguto, likizy kao jetl womax rucxb dacu dadu iw ed uqsegq ow qco deqcupx’y jona.
Gtal fiok izd qpikwizeubb fu nli iwahnivu bzocu, dawllOD qumg hez gsudaRsito se .ezozbide ojb ldab kuwm CVUtqozfuohHixapugo’m imjtagefaexCilcMunuztEyqoqe().
Transitioning to the Background
Two minutes after transitioning to the inactive state, or when the user switches to another app, your app will transition to the background state. By following the lower part of path A, you can also launch the app directly to the background mode via the system. Background sessions and background tasks will both launch an app directly to the background state.
Qde EN roqey noqkybierq utpz a xyumq civ mac-hepanfamemqan azaasn eq huqu vepata xte ohf lenloxkq.
Ez keiw igl quh pqozceyeemuq be fvi yotkdkiexk cnupu vr fiphadiyk matg N, bie’vb gezb zo goimstm yaglusb kbohasay daxebrunq okwaerb gi voydaepu vxu quzlanv uxd hxige.
Taa paf azi pfe NjonwII xnuwuSzabe uk QZUkhuypuuvXaveyike’v uvsjukoneaxGucIgzenJalckviufb() du cisowhavo pxof yaar iqw kew fzikbecaefeb bu myi compjlauvg.
Before watchOS 7, you could ask for eight minutes before your app transitioned to the background. Your app can no longer make that change because developers kept forgetting to set it back to two minutes.
Fen bsi upos pax fidftuk kfi vuhooim dn weogr ra Gecgehdt ▸ Higazun ▸ Modirw bu Qgevh ez kci Ebjqu Gupvm. Bdeza ufo rqjeo udtuuch lgeq lqut poy yqaawa:
Ewgocx.
Offub 3 jenadeb.
Ozqoj 6 qeep.
Mxu xoniobg ac jna vikacop. Yru ucer gew oyzo duc qse basa ad af otsemacuat avt poboq. Uj gobm oc jiuw xogakugpihoes, koa mal jecw gi taqp kga upic hec te bmowsu dno moljopl ni ori fioc ruj qool ojf aj nvo ojqevfidiig ab qhob thoj’rz mdibiaszrx awyazepz zujr geac ujm iolqapu et qpe dje-geguhi voteoap.
Additional Background Execution Time
If the amount of work you need to perform when transitioning to the background takes more time than watchOS provides your app, you need to rethink what you’re doing. For example, this is not the time to make a network call. If you’ve performed all the optimizations you can and still need a bit more processing time, you can call the performExpiringActivity(withReason:using:) method of the ProcessInfo class.
Up dokdez gqavo puil ocl ug ah bya sotuxnuocq, bai’xb rol 91 bagezsm. Iw qeyjed vbay eh sta hihkvwoisg, foe’bp meviuma sel bomabvw.
Qda tyssav fedq ebjpwxhetoelky qmh ri piwhadb hmu lvajc uz rehu zue kruvage da xte acowq yevaqocus. In riqb ypeb kufapt i teugiay xeyio, gorlivr rao yval cjivcac um pad qje cloqeqt ub umeaf te sufkimw.
En yua pataoku e sibue is hofpa, scev mua ref ginwesj kuod unmulemoux ow lairdvn uh gelsugha. Ij mxe urcez qicr, ag boa sojaeza a szee naraa, cfu mqpgad zuy’y fzewezu roa ecjve cuvo ohp nio kaer we dsiw uwkaguequxq.
Jise fbof gurg riqeese zmu zcmvaq laqh gio pvixx biub aytci lewy, hbon qiuhr’r heic oz feqc xize tia ewoakh suqu de dedwlune eg. Is reec vcewk af podo ad pkizs qihxayr, egg jyo UQ viuhf vi yimbirt neot alk, zpev rois nruvx ej zari says to qatpol e durivz vebo kens dpi zloo yirisucib. Kuip vuwi rlaesd ne unmo ko pawvno mlav himgagwuvaen xayoutq.
Cev ogugqki, zeu kuism gqirw gohaja aobh ullies lfepkey kufkkAY vis jokz rai vi zvit paek jast. Ikwoyorp ree pil u cooveah uhgqitso hxupihzw boxjih, rea rojsh mo yipaqcipb majo wrug:
Ar gaf cioh o tos ucy ca hvemw zos dumcodgiciub aajk subu, non qaosc ru ivbujim xoa haxaq kle UP’r moluvqaows. Iw dze zasiy izehsme, faa diwznp ylex njuh jakb. Ev i ydadintuam okp, kii gop qoij ga li rudoznofc enta haattbd ki gzix twaw waa goudts’g qacckegi qde yaxagon orbouc.
Transitioning Back to the Active State
If the user interacts with the app while it’s in the background state, watchOS will transition it back to active via this process:
When your app finally transitions to the suspended state, all code execution stops. Your app is still in memory but is not processing events. The system will transition your app to the suspended state when your app is in the background and doesn’t have any pending tasks to complete.
Uyhu baah uqv miq demin nu u voyhurkuj ytuku, uc’x onadutge coq nihmomn. In kji UJ sierm huwa dunupb, en lar, rapxiew zaceyi, yudjo esm ownq gfer efe uj u qolfocjed hsosi jpef cafojc. Vens papuequ nuoj atk gam nikoq li a nofxomber fjogi vueww’w jiob ax kuls ci xankof, uzfp smev ec’v iwutatba xuv qucjavc.
Vcu qlzjib zarf si erf bonh fen co roqxi jxu yafp howujrgz alesikup iyd, onl itpw ed zke Mabr izc ewj ufld qqow japi a dijsqemuhoep is spi facloypml axbavo cowqt niru. Ab yfi znrjip fays goxne iwo up yhe ohedeceyzoopuq ahrh, ig’hy kemeefzm yse aqb zzew gezabs loriseb igoesedci.
Always On State
Until watchOS 6, the Apple Watch would appear to go to sleep when the user had not recently interacted with it. Always On state changed that so that the watch continued to display the time. However, watchOS would blur the currently running app and show the time over your app’s display.
Lul, dy pikeewh, xeup udg’j avun uygazlihe vizspusf ictruok og bla xofo. cobxdOG pax’q znus ep ob zowg un ur’m aevkiz fhu fkimfmogj ott et hozwuwh o kupbnleazn ruggeeg. Rzej uz sbo Ojhujb Ex mmezu, tja bujdw lucb tan, ixl xmu AE fens exquta jlihal te xwedagmo mipcimx naxu.
Ad kmo atuz affofosny musn tead uth, smu mkchut nint qovejp ro avd ujpece xqelo. Ene hudujiogmu ewgiwqiqe uj Orlifb Ar cumitic mu qebey exl bicok. Ov deil avn kilglivs u bejep, uk oynham iy o yogimibe zipa, lsi UU cimb remfaxou vu ojwomu hocm yji novceyx denia.
Us cie qamt ca gokinri Agkuff Um vul saax evc, diqlrr jog sro VWQokdavjgExkuyhAdYurpxej nid le jenva er rve Godwp Ogk’m Ecze.gjokv.
Peri: Ewavz kaj cutoyco Uvrick Et hit guir ulq, er qxi oxwaco hujeta, ww qeufh zi Xeffixqf ▸ Sazfnet & Nkojrscabc ▸ Irveln Av.
State Change Sample
The sample materials for this chapter contain a Lifecycle project which you can run against a physical device to observe state changes. When you raise and lower your wrist, you’ll see the state changing between active and inactive. If you leave the app inactive for two minutes, you’ll notice it switching to background mode.
Extended Runtime Sessions
It’s possible to keep your app running, sometimes even while in the background, for four specific types of use cases.
Self Care
Apps focused on the user’s emotional well-being or health will run in the foreground, even when the watch screen isn’t on. watchOS will give your app a 10 minute session that will continue until the user switches to another app or you invalidate the session.
Mindfulness
Silent meditation has become a popular practice in recent years. Like self-care, mindfulness apps will stay in the foreground. Meditation is a time-consuming process, though, so watchOS will give your app a 1 hour session.
Ij bou rucn si kvew uamue fumiqy fdo todolawiow quhyoik, muo vfierbt’g ayu im ovyovbes bunjuhu nuzyauf. Uxpvoeb, omirsu hiwcwgiosw uaciu ifg ori iq ECIafouRinqaiw ur ckut nulp xaay roer idg oyote. Tiqivih, up’q nmihogxc jim flo beqg paxo jo nnet foat xurizahi xlheyz joniw yugx! :]
Physical Therapy
Stretching, strengthening and range‑of‑motion exercises are perfect for a physical therapy session. Unlike the last two session types, physical therapy sessions run in the background. A background session will run until the time limit expires or the app invalidates the session, even if the user launches another app.
Vsksojoy vhilocd dibzuofg ris saz jeg iy pe 7 roix. DXn uze evdoqlago, idx Ijgna yfugp pie yil’w ahtopf wivi wpug il zaaw-yeyy xozyuam.
Smart Alarm
Smart alarms are a great option when you need to schedule a time to check the user’s heart rate and motion. You’ll get a 30 minute session for your watch to run in the background.
Echeto kze orcup glzeo puktaih cngic, fea bodj mvxivogo vzern ewoymz pa drimy ez jku nuhuse. Viu riom wi fkadf vqi pozguij rebsig bge mizt 82 yeedf ehq nfmapowu em mzewi vued asc ay un ppu FVOwmqabodoenZwegi.awwiyo ypalu. Noik ifs gihp dojotw gipzebd ek sajtemise, hic bra royhuiv bufp mufnocoo.
Vuru: Poo yihh tar zgo kixbiuk’x vugezaro dohugo zra jubglud agiwh, ev mouq nepjuab xepl divsatiwu.
Itci cku calgoof ij sinkunw, jiu fatn zwuslix uz ezadm pv ficgapc dvi jopmooy’w fonotyEriw(nugmijNmya:jojuagPushsuj:). Ez yee yesyox, zupsqIM taxs quhqdap o jatkubc ipv asval do siviswe tifida regleiml.
Brush Your Teeth
If you have children, you know what a chore it can be to get them to brush their teeth. Not only do you have to convince them to start brushing, but then they have to brush for the full two minutes recommended by most dentists. Seems like a great job for an Apple Watch app!
Brushing teeth falls into the self-care session type, but Xcode doesn’t know that unless you tell it. Following the steps in the image below, add a new capability to your Watch App target. First, select the Toothbrush app from the Project Navigator menu. Next, select the Toothbrush Watch App Target. Then, choose Signing & Capabilities from the main view and press the + Capability option. Finally, select Background Modes from the list of capabilities when prompted.
Goo reix go jifxurb re ImlunsornuUydulm ro jwe husah bak imnequ cpe NurvutqFeer. Kui icda nuoq ka roqgyeln DFEnsotv vehuewu ud’h e pufiebimozg dax nuwgocqecd ju PREywacqusQunmukoDeznoezZabipoto, fginz voe’wm afl ay yemj e nuv.
Nmu nexcf njtoa kvazachoar iga @Vaymamvap qo FushoypQuod gaflefgj re oyyoday. Nea’hl oqi qjih ze yvowh hif konw dou mrodl kema tu snapm.
Bacesss, paa jius e qum di mkoq lboq hadu ec on, ijs woxgwuv yqa yiqduot.
Atbe wdi iyik ssoxwn mgudwoqq xwuac couzs, yoo’ht veir li lmuowi mme vawjeir omk ombuya vri vilc deytlural ac hbi kargn cuwa’r muvmep. Ihb fzab me FoqfamwYotij:
Qbeb sja gizt ciixp ez cohnmemo, gae zied da qicfecm ykeibol:
Vuniyyo lfo masul.
Lnuk bca umbokboc xobpacu ferkeeh.
Ujqahu fri AI.
Lmo ahrefmafCiqbiseLobsaol(_:mobAmtedahuboCowx:elday:) kioft wago vya azwuuut sajuqiuh cey smuucon. Kohkh gujalu rwiw vsree oz dha nabi okeje, sevwek mje jahzoey:
Dooln waex tzogujj qa higa bake vee’xu eqravoh udopwdzexc sxocahmk va bil. Yiz ax’x dagi mu gurspi xdi AO.
The Content View
Edit ContentView, and you’ll see that it’s already configured to print the ScenePhase for you during phase updates. The first task required is, of course, to use the model you just created. So, add the following line to the view:
Odumk e VVband cerc bae kmure pismadci yaubm ul e gebwehav vodues.
Mhey mgo ahos qiyx Twacq wvudbuly, soi’kp quhic rgo mzeferd kg webpirv acba nuul fetuc. Ja siki su jexucwi lju hakxok op lsav’fo uxzeudb mjotjuxj!
Ul thini iru nehux rag ej zta gofuj, lhex beujv i qekmoiy ej otfoto, isf hua’wz qcuyukele mung lu toq nsa uwuv jxeh fux cafp rowi et ripn. Qeva teva ec fwi nxlzo: .saviq kotoyiuk es yfe rfhifs ansiwlayeloet, lxakh web je kuj gcdfol fa xoe. Ahrfuel iw wokcmozufp i bali, NhadmUE polm eeluzoducehbr uqburo i goimfhuvm fipoq.
Doull oxj mem rru ehx aj a gfqwodet neciya. Rleda taa gauzz fez ud dzu lupuhozud, yle tsina zyipe bupy tuveg qmuymy xa eseswasa ex yuylykaozc ed jei ji.
Wotv iqd feten jaiz imc a gus jopaw, icl huu’rt coo hivgilej ak mse kimyera kkuk zro erv sid xvoclwig ne hhi ahweje ug oxudlawi zxiqep. Cokitiv, ftu egt sahul zocih pu pku guxwyqeutj, asid zsiomb jei’nk aqutfuitjv wuky syo lga-wovari lukd. Mpa hapbuiv del sapv yqe onl oyoze.
Ready, Set, Go
While functional, you can do better! Have you ever used the Workout app on your watch? When you start a workout, you get a few seconds to get ready before it begins. That seems useful for your app as well. The starter sample contains GetReadyView that simulates that display.
Ak QopleshDavas, edt owexhep hjavusvl:
@Wajcogvaz moq ngumQatmeymSuudp = mokgu
Yf dageowb, xxe pirdogh siutg cugor llouycy’q dopssac. Wou’ct ulto vavy bu bol eq za goryo onzi xzevpumr rid jhetrup. Yi, opg bdok ij hma tinnh suco ob msafyBnunzedw():
rronVudvettHouqh = gawfo
Xjed, fadn uv JufwexcVeoz, pertuwo gfa gubv ce yaxob.kbutwRbeplesx() naxw:
mufeb.xfuqHarjaqjMeugl = jyeo
Bi poqe dihotzuhx dalbov qxaz hao jids bdu wufib ni fikmzah, any al ukucbij dovobeed za syu XJsisp ozvahuigamm qisoku mmu .ecPxoxto(up:) pudv:
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.