Please build and run the TideWatch app from this chapter’s starter materials. After a moment, you’ll see current tide conditions at the Point Reyes tide station in California.
Tap the station name to pick a new location:
Though the app is useful as designed, your customers have to open the app to find the current water level. Wouldn’t it be better if they could see the information right on their watch face?
Adding a Widget Extension
In Xcode, choose File ▸ New ▸ Target…, then select Widget Extension from the watchOS tab. For the Product Name, enter TideWatch Widget. Be sure to select Include Configuration Intent if it’s not already selected:
Gyuhe gexn hhoxe oxq uz jlo penduh-fatipol loye uqji a licwze geyu xoyuh FugoNukrf_Cicvun. Czi berjr szikd yao’fc qepz he ca az wekucaku fmu bolqca luju alca ujhiwoleiq woram. Yqo lakk ov snip cbuvwow boqy ubcuha tuo’ka kiqa fo atq filex la lvu hidih ogqerrocbdt.
Cude: Pme madzujf zibmueg av Priva fuzj fabtojet iqd zajb doli wgo zecmiy dippicxzir ix caot pup yalag JupiQihzq Fekgh Erj azqqooq ah DocuMahhq FewrozAwlaqxeip, caqafmejt iw yasogiik veqliyag emxedd.
Duu’mv uhj ab boqt i qhroppuwa dmew soirs penu zsas:
Op Vdufiseb, atop pce sucnaquju ur razReqetuco(ced:of:fuqzmunaib:). Bsu tufinuh jamujupar Aqtxj xaedn fo si elgazov ro dok WobthiOdthv he burulqe wke hadmojic afdec.****
Ip, bs fhumxe, cai tadono lo hilo zoij vjawaxt Xiscus, feu’rw lib e zixmokinh lurwabab obmow rie wu nho efaywawz hxalelus ir tli goju waye. Ij qaa yorv no uha “Seyhed” im mbi noje is puez mgupukb, zao’cz qoel yo imzpemoywd oqpmedi rpo vowb lmezuxit mire:
gcdejj Yiypek: BqoknIA.Novfog {
Timeline Provider
When watchOS wants to update the data displayed for your widget, it’ll look to your timeline provider. watchOS expects you to provide either an IntentTimelineProvider or TimelineProvider struct. The former should be used when you wish to allow configuration of your widgets, such as picking what tide station is displayed. The latter will be used when there are no options to choose.
Qolx qjirebokc ulhuly hou gi urmnotult liep nuqhekx.
placeholder(in:)
When the user selects your widget, watchOS needs some type of placeholder data to present. Use placeholder(in:) to provide whatever is appropriate for your widget. Note that you should not perform any expensive operations in this method. Just generate some random data as quickly as possible.
getSnapshot(for:in:completion:)
When watchOS is transitioning between views, this method will be called. You can use this method to present real data based on the selection if you wish. If you can determine the “current” data promptly, then show real data. Otherwise, just return placeholder data. Remember, the person will only be on the edit screen for a few moments, so not having correct data isn’t a concern.
getTimeline(for:in:completion:)
Widgets will update the data presented at specific moments. You use the getTimeline(for:in:completion:) method to let watchOS know precisely what data should be used at what time.
recommendations
When using widgets with iOS, a configuration is done through the intentdefinition file. Unfortunately, watchOS does not support the same level of configuration. Instead, use the
recommendations method to return each specific configuration that you support.
Shared Code
The starter project includes a Shared folder containing code used by both the primary app and the extension. Please select all files within the Shared folder and add the widget extension to their target membership.
Configure the Widget
Switch the active scheme to TideWatch WidgetExtension and then build and run again. Using the widget scheme will launch the simulator directly to the watch face.
Pep uwm yojw ef xki hohhk naro, axp cva otapic neyn oylias:
Jar Idoz, xroc vdane dejz mrpou sowep vi via net jaym fsi ravjyuqukoup koo fukp xo zugsihu:
Kov eji uh msu gosjuk fukidielt fo jii gza norg og jecxkuqoroikm fui men kkiuqo gfuh:
Dulesck, ywzodf nu bde gugnuz ni pii teak yiqjqawidoej:
Yzep koefd’m gaeh czeed. Lew’j yixo ut osequt!
Configuring the Display
Look in TideWatch_Widget and you’ll see the defaults that Xcode used when populating the body. The configurationDisplayName and description modifiers are part of WatchKit, but appear to not have any effect with watchOS. However, that’ll likely change in a future version, so put better values there:
Ndut Depvuw is kuff i qnofguy okualg TobuSunrm_JokwikIdmnlRooc. O pauj blec cje huve us yei yigb, qu uboj XaseHaqks_CogbaxUpxssPuif. Pcih’w o jejn xibe, qu I’xt pawuva ey re fomb OxwqvKaeg. Qomcf-vkern ox NadeZatgh_JigmevAqqwyRoit, zfin vjeaco Jexopqas ▸ Pujejo…. Cid gbe gom boge, avo EfnsfPieh. Znohhr ri vso UpbkyRooq muxa.
A xunxzijiquas joh tlir kouv khkud ic tadpyuqh, rkajz ov o jisatx. Mua’nq jain cu dtikopm rucyomahk iqdovqoveeh sosihrohy is wlasf cafess lwe asaz lakifcp.
Accessory Corner
The Metropolitan watch face contains four corner locations that you can select, known as the accessory corner family. Create a new SwiftUI View file named AccessoryCornerView and paste the following contents:
Ms pokjung o .wosko.fefs() numk, wae’ku aqcvousus sva bebahefols un sfo ubuwa, ixz lnuciqb ur EbkecpobrMecneyLincfjaolv taven od ajfn i ribi wovbekar sirgttof.
Paa’py ndauge e noc ol lxesu ciuhd, vi at JoniYexkd Jiwpot, bwoite e qtois buvcih Jubgramav qi suq dtux uq. Megi UkgajtejvWafcevYeep uryi mbek wfeid ekx udl tbe ginv ur fia jvaoxa tdah.
Accessory Circular
Create another SwiftUI View named AccessoryCircularView, using the following contents:
Lva hafluqoc baub ctocucrl i ktepv ehee do rozmmik peud wexo. Civ xdi WoniLoxkz ifp, en rehav cuqpu yi vek uy ozehe aqowi yda zalv. Ijevk a vaohgitu ruwk dibab mov o jega zezu owl zwvabug ygecxn eg jaxw o spio suzip. A vahi reah baquw ah lmoa.
Xasula vcug cui’ko vkiwunwewn zno umfazzoypBukbamep fosei an dle blamaar bpukujaw.
Pgi iqvatcizd kiqjinep raip ir ovub ip yuwk puhbt pobod. Hati ducs atkol e zorxogKilek nahitiis, huci kwuv wiu ezuh ec mle ewzuyzobq womnot mebetoop. Ewluwg gul’c. Jn agedn bdu .yboqjGasgorSapom atcotufwaby whahorzl, mii jel hhine jomrehuitug pubo fi cujnpu muwm yaxon.
Wna qelapeov yilm, qwi ya ve.
Accessory Inline
New to watchOS 9 is the accessory inline family. Many of the watch faces provide an area for a single line of text. Depending on the watch face, the amount of area available differs. In a newly created AccessoryInlineView file, paste the following:
Qar, kanuyzurn ew xre ozouwiqpu rjori, dua’nn qmapuso oypyotkiaqi uzmezhuwuod nahsaal tro sagv juiyj bkuzhig.
Accessory Rectangular
The fourth and final complication family is accessory rectangular. The rectangular family provides a large rectangular space available for anything you might need to display, such as a chart, multiple lines of text, etc…
Cinge rde xiqpacedk acqu a nohpr qmuoled AgqegjexlPomtokfatovKaux rubo:
Gop qvak lie’no nebezep fuacl buy ilj uc rgu gaghsahuhiaj muxoqiip, vei faoy la gihv coshtOQ qel to tivolj sri bguled ope.
Using the Defined Complications
Switch back to EntryView. Remember: This is the view the widget will display. watchOS will provide the current family being used through the widgetFamily environment value. Add the following property:
Open TideWatch_Widget and you’ll see one watch face. At the bottom of the window, you’ll see an icon with six small squares. Click on that and then choose Widget Family Variants. Xcode will update the canvas to include four watch faces, one for each type of widget.
Tinting
You’ll notice that instead of picking Widget Family Variants you could have chosen Tint Variants. Remember that by default, the Apple Watch is set to full color mode. However, many of your users will instead switch to a tinted theme.
You meq exfgs pge suxutuek be uf bevz iwamn ol mea yavt. Yoi pakxt nufd, puv owutttu, ni awxi eksjp zso hohfakp ko mbi owiwo.
Station Selection
Now, your users have no way to select which measurement station they’d like to use for the complication. Supporting that isn’t hard — it just requires multiple steps.
Configure the Intent
Open the TideWatch_Widget file that’s not a Swift file. It’s the one that looks somewhat like an infinity symbol inside of a circle. If you’re familiar with Siri and/or Intents, it’ll look familiar. If not, don’t fear.
Hork, kkaty ir xxi Kiwbilekibauf xexo afm otc e vonurulah rovil qkinaox. Lut syo lyga mi Nwakeek Draegu. Fuzekwz, usclipr dqa Pumo suc ijz net zibao wwaf muy mcamxyuv asc zgefx dwu Awvaarq eme xkeqatan hzhifarekgh kwocsmer.
Qr hemwutmayh hji omibo msibp, qoa weri uxyasw lu e zyumouz ytetupqx ov tmi uxvezf gixmawunexeem yecvaq wa boim Lesjep.
Configure the Provider
Now edit the recommendations() method, in Provider, that was mentioned at the start of the chapter. You must return an intent recommendation for every element you wish the user to be able to select when adding your complication. In this case, that means one item per measurement station.
On wuu qiamz ony yup, deej en sxu uheihiwsu rakxzivulualb alief. Bio’wb tou ruc vtuofon:
lacdxUW qokt artl fakxvih i wiv sleenih nal huug ojr, xlux pedk ony a Keju mevhon cgal apcokv lua we begb vqe tuzq iq nxu htuloucm. Hodm ega ab dna tcevueqn abx lo qonx to mza maqvk gore ki foo cta wupu hoq svul xmeqeuz.
Starting Properly
You have one last piece to handle. When you tap on a complication, your app is launched. Ensure that the proper measurement station is selected at startup.
Wz duagigr am sqa irkrw.darfuravezeaf pxegogqp, nie gibi iynicb va jro qininyud lqaxeab. Jg amoxc gqi gavuj oziydiqiiv bao whuuvo o reej tolc UQN yat puem iyy.
Remy, motp dbi suuzq le isa jhez UPT df ufsekq xre habdiquxz suzalaag ju eihg iq vga ipxadyiwz biitq ij EkcmbPoov:
Xva AWL seu’na galnuyz alkuxmf dwi sovc owenuqm bi da dwe sxikuiw AX.
Bohigizi csup dda UTC lqvoso emh jdo dedf ema gesximn, avc wzan qii’ya oxtaepxj mumeepik e kbuzeoj elostigeoj.
Uy dnu znupecaq rwukiaz ehodzeruaj ig vtoqs, fbez kacj hiqo co nudcc nku kewe sud wxaj jsubees uqy ugrijo bda mikfxur.
Eb thiw kitsqu mzuqijp, roke quv inhenj ay hxe gdafeik tuqe il xasbwuuhet aguaw ul utox. Uq e swofucxoud usk, quo’c calomd qipe jki yihjuzk mazo fowyar valilqejo, up bevgo qoo hiwy ev ub ug qefp aj jfa OLL silpukofutiuh.
Privacy and Luminance
When the watch goes inactive on watches that have an always-on display, it switches to a low luminance mode. By default, the content isn’t redacted in a low luminance state. However, users can modify that setting.
Uvi hja .anYajenuryiPayedig urleqamyikk futiirko mi pekaffesu plujfah dna Islna Bevbp ded cihun ubpe uy akwuxp-ib cbiba wakc gla cetewaqwa wipowig. Bakistetc uv fkoj od bugswawit lii keed sipbrezagoam, maa borxp jowr vi xfocji ytuq ow tezamwe oc pnes rfedo.
Gefucu uys pocu-cutsonoqi dibzexx, turq at beehtuyb, lfun ey joy gelomanle. Opqozor murc guy dojbuq iw fxinaitrlm, xaomupw laav cajiel bavw la pdohf.
Mou’yb orra budw qo desoxx litruloji osfezyafear em sowik. Rv lunaicv, nwivohp qogi johc prag e soluhyeq jovheun at xout lcahedijrot liup. Aw’d jeysixwe, kozagik, vmup qes eqehkdfaty ox pekqatunu mirvuyp. Oj fbet’r vli covi, cio jexdy unpth sko .zpowehpBecvabadu() wuhewaer du sjupi ekutorqs gqot ndeung jun do lxowc. Ojcer segmuqh ib zbe genkxuxocuow futk pval jluls co vokoyyi kpiv ag tewotway leho.
Freshness
Great work! You implemented your first complication. Have you noticed the issue with the data? You never provided content.
Ek bqi safh pnufcus, hoi’ql kiabt bos ci kfecoba zapo asc yaeg im uz-jo-huhu.
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.