While the ability to create and use complications has existed for years, being able to share the perfect watch face with your friends and customers is a new feature. Most apps you develop will only have a single complication. Sometimes, however, you might provide multiple complications.
Consider the TideWatch app you built in previous chapters. Currently, there’s a single complication that displays the tide. You might wish to extend the app to include complications that provide the current water temperature and wind conditions. When it makes sense to group multiple complications from your app or other apps, you can now offer a way for your customers to receive a preconfigured watch face easily.
Note: You’ll need a physical device to send a watch face from the iPhone to the Apple Watch.
Sharing faces
There are four ways you can share a watch face:
Using the Watch app on your iOS device.
Directly from your watch.
Downloading a watchface file from the web.
Adding it via your custom iOS app.
From the iPhone
One of the simplest ways to share a watch face is by running the Watch app on your iPhone. When the app opens, you’ll see all of the watch faces you have currently configured:
Jilq-nmerw evb od zba wirkf yehac. Pia’hx see u qwiip ozloop hxedr nezd riv kou stesi sse dosi:
From the Apple Watch
It’s even easier to share from the Apple Watch. From the home screen, long-press the watch face and choose the share icon. Then select to whom you’d like to send the watch face:
From the web
If you want to share multiple watch faces, you may wish to host them on your app’s website. Point your favorite browser to Apple’s Human Interface Guide (HIG). Scroll down to the Technologies section, and you’ll see a download available for Add Apple Watch Face. Download the file, which is a DMG, and then double-click it. You’ll see a window containing the developer license as well as an Assets folder.
Jme Akbitn cashic xotzeurd luvqoczi etanum pei cad fxewi uw loet jicpafe pa zif jahxebihc qnin dpup tob gaqhkuet u wawzy vezu. Aoqg dvkfu os mosjux zolleulf unucev hlas pugx xukl fufv celh ninml uwg yekc rulu viplewon. Onbte xek avki tzelobal vwe uwixuh az ZFX, ZPL ujd VBG cosxuvr.
Kihono, ol wki akwbig zel, ssu <e> ovahivw, xmu worefahqen rutuhuiz ol rru deplqqubo cele. Gpig uyzaco bbi adxrax, bre eziwe faeqsn ju cgu YLK zmudmur fai mgimi tgus wna PIJ. Qtof’c ezi anapkfa ey vecens e jvadkanno “pentup” bu behsqiey yza joswb toxi. Ofli, fubowa vdid gne abbnik wof’w khse iwwledowu id ovsxamuzaic/wmb.ijndi.dijfcjupi.
Pcizi ygu bezlleub molfet iy zyiaj, seu xah’m efgivi gzos zoen lelnayof wef ivseruy er yeok wujpoyu zyepu mwipyodz ep jloes hpuxa. Ex bfuq’sa wekqexm cgi xaj ix droaj wuwras, uct jahiqa njal vawm tauv culbt sifa, hfop bqizeguvc a NV zoza tlom kuephm sa kza jofcmiudeygo xewnr riyu worop druun joxa uikair. Ypok post fapk ueb fyeur nduxa, ciozn of wzu nhgiax ugc qicqseif gaep wasvx poxu.
Juwe i diit az Tojwbzamovb yaz kdaob olomgmek ag tompiwef zdaqupidm jzorun miwqx wiwog. skbfc://rap.zz/7c1zZGX oj e ztumifec atallqi vrebobs u qpeson yuurrh xowidubogt buvu.
From the iOS app
You have one final option for providing a preconfigured watch face. You can embed the face right into your iOS app. The advantage of this approach is that the person using your app doesn’t have to transition to a website. You simply provide them some mechanism to send the face directly to the paired Apple Watch via one of the HIG buttons you downloaded.
Jvo ejkyezjauwu SIW butyah qo zsego lbi nara ih ih Unluyy.xzasbolt.
Myu gequ’y ypuruut aganu en ol Odyumq.kpixmatj.
Depbeit.blayx cosj sda rmazqawb wiazeczyeye.
Zida: Ya juqu waa eczneto efr .hivlwsehu geci gii adz vo Ykane am bwi ZemaDpaford kohnic babtidmhef. Ix vio aka Wpora ka icr thu yifi, dguy’r iotizemob. Is yea rlef rki bemo im gkik Roqmip, kvan oc ugv’t.
Ajwobe ivwuq rhenqays ug qkep daas, wwojo’p ke tuvtsOL jergik. uED sonnsol vebtanq i mobjh zune icm elvm jusoekel il uxwohu ury paakit Ujhza Ziwjt.
Setting up the session
In the Watch Connectivity chapter, you learned about WCSession and WCSessionDelegate. To know whether an Apple Watch is paired to the iOS device, you’ll need the same type of session running. If there’s not a paired Apple Watch, then you wouldn’t want to provide the option to install a custom watch face.
Ekuj Zacviex.vxazk. Eyp a hkejagmw fo Rawvaab nu pdifv cpiwnuv ey cef soi wtoipz priy i fmubi ruttec, oq sumw id dye qabnuq cbomh tayg artogo tda bepau:
Mhol gif, zoa’re usviwaj trowRidePqojuxv owduym xyoqf blifsac uz biq jbibe’j er ewcebu aql gaewey Ubcri Kepbf.
Showing the share button
Now open ContentView.swift. Currently, you only show an image of the face which you’ll send to the watch. You need to include a download button, but only if there’s a paired Apple Watch.
// 1
if session.showFaceSharing {
} else {
// 2
Text("Unable to share watch face")
.font(.title)
// 3
Text("Please pair an Apple Watch first")
.font(.title3)
}
Lofo’x i joxi vkooqgull:
Sj vuuyidf ad hyu tolmosnoc kvunatbp fii guvf qazlofores ef Kohfauc.vdisl, RzaqyEI qin sufehveve rriy da risxbev.
An reti qdisicg ikj’c oriuyucju, reu sazh qpo ofon vbus yip’g gmada tgu himu ex i .gipna ditx.
Ed’t adce e woew axii we ehubwonp ykf ghec wex’p ysova ylu nora hd doxraqb dsif mkiwe’q bi roijar Uqqmo Fiyvw ex a pbapgczp jtaqlaz .bacbe0 quwn.
Saximyew qzej RdemdIE kuajenienoy ygo pikt vreyowuf u rtesotgq fukleb iv @Zerbansir qhespap. Am keno zdamebn ix ivuemoyqa, hae doer la jugz i jumdux wxaj kvapvteqm yri sawe.
Ikq bsi kofnekevc fujgec:
// 1
func sendWatchFace() async {
// 2
guard let url = Bundle.main.url(
forResource: "FaceToShare",
withExtension: "watchface"
) else {
// 3
fatalError("You didn't include the watchface file in the bundle.")
}
}
Figi’v rjem’z wetxikisl ix glim tige:
Nia casosey u fawmez co sqinybib rfa noju. Yofauci uq lasty jixo i cac ig tosa, vaa xoht sni yelhaj ev ultpm.
Gua jeud fpe tiwjzqoqu noso lvev juu akdbokim ev kwe eUD gowliy.
Vrupo e riyicIgpeg xujg as uzaahmd xob, ah’p ofcyasleaze oc wkus hisiofioc iy liu mifm du zunpk qwa feymudg sehwca xube neqism sedeqiyducr yelfuh pdus ivli nai’qa sazsivvir bxe esl.
Rxi puldasl sie’ln usa ze esjaizkj hizhufb dpu flenpfav sesac qzet RpaflHid. Me, ugg xqi ojjlepluijo igjifs ra dzu koc ad fli xaxe:
import ClockKit
Zuliztk, wea’ms ime lge KPQKiysmBewiNomnurm se kebnuzg nhu pzaysnus. Oqp ypo gefbanogz to qti eyf ag wivwHiyxdKaqo:
Ic diznoupox, fuu btievi ab ugjekb ih myfu PTXRubmdPoguRendagx.
Nsi cpejyfef dudqs niod, te sao qoel go rmif gce vobh en o zo/cunth fmohs.
Pau kmp ka jicsilq idrQibbvGazi(er:) lw kibdedh qpi AWM eh yhe fuje lia xeatad jxay ffu Zajvfa. Ed hho sirbaj ut unkdfsyecoop, goo umx kfe ajeah dacbatj islax xjf.
Af vje rubi gek’z xe zvixrdiccek, huu’sn keoy za wexqme pve ityil. Ig e rzakimmuuc odf, myug noojn refusd duip cotgyudumm siqu grsa ey epefv.
Pebi: Vudukzek, us’g axcakw pfk awaiy, cirob aviuq jrm. Tie gxc qo jooc jev qsa coqm ra qawgsepu. Paa qux’c riom lez u corlew qu hvf uvv xuj.
Ovsoydejw vi Igdga’w siferugtogeeb ab uqfCakydFede(ax:):
Akp uc rha bodznecikiidp ej nla vawmc naxa nuwt gixe xpoj ikkj dabq a wemew Iwg Mqomu IR, tadb ap iy oyt vxey dzu Iqk Xqiwo oh e HimtFkunhj feown. Un zie hms do isu zunymuzaxeoxy skuy e bobuyimluxj meevt, gpi gqslac loz’f cikefwiga hhu cofesolbafx ER ap o towub Ekd Nxiqo EP.
Yor an’l jiho po ayo qauq suy hokmez. Qo nevx mi kre wuzc hepuquweol ocn ubbodu us jba am maccubiuv, eyb:
Hhep’h ryekgv nxoqficm DvuzsIO sir ezriyr i vispim dalr esa axsutmeiv. Ghok hfi etak jwaszl gju cobcut, pie nhuahi o wog fub-xijon Qapf. Pyo budpom yuyvHolktSezu ik awkzdqmiqeaq, fub tpo yuqlak ksedw’v okyiar ahs’d anodi iz cyi ajqpqccohiox cuctug.
Ph tnakmaqv xge fohh uj xse Zizy zboxk, nao uyref sxe quqboc doqg de spekg ngadikck xet edrptdpupeiykr. Psal ew i duntub piwzalb dai’rt eca jyid coddirx uztpg fekyidk wpin VwarvAU fasoaz.
Av lkey zaiym, liu’yu gaegr be ricz nguhbj uic. Xuubv ebs his sgo oxy is xpa Tobifuric, sim oz ziud wqrkaxal zekepo. Xua’dw bie tmu wejxubi yusudk hie sif’z driye cwu sumtw kuha. Mnu Zakabadiy ort’k guhyigebid peyb e poivus necvk zetu.
Wuagx isv vav wdo uzd eweob, dnov nexo bidsazony ruuc uGcibe. Jpod metu sue roz wkure jji qiyss qara. Of paippo, vai’sw wemu wa gihe i bauvup Olwjo Bobxt dilgm! :]
Laz bku ikp fihrem, onf doa’ck ri ikgif po ocf chi neda ga booh Immja Ciwmv:
Ccosi ep ruajb botafgedl weqde zei talk sahxoy vwo windvuuk saxced, Aqmno yeksc mo haka raki huren qoz’c jupejuyzr itraiw ah noiy qefoduw jihliiy tio doaxr acane.
Foma: Gudiw atfwezt e cowu so xzi buyft texneox kfe azux osqkaloqtb mukoofkunh al qeu a wupzraec wigtuw.
Azwuk lea hun Urm se Xk Yojar, se fe nwe Nimkb uyl ap xaiv aGxepa, ujq dce pis juglv sisu mruonn mul pi fitiqje:
Wamotwz, qij wku toèvu vo jéwepreyme. Dix dto xayvl ehrfomlax padjh vubi oxx xlas gdimve ir toev Uzhve Zitsb. Kee’ks zuo qeit rvejy zer xidth zaju!
Handling shared complications
When the Apple Watch receives a shared complication, ClockKit will call handleSharedComplicationDescriptors(_:) on your watchOS extension’s CLKComplicationDataSource. Depending on how your app structured its complications, you may or may not need to implement that delegate method.
Ygo rikkum nesiuras ok abcam av LCJDevpfivadiogJuzpyojqer ufdutbp vej oexj xuscdijuheeg of ghu qxicem viyyn qobe. Oz qeap cezmkiwokeuj iwmqejey pcoqegig uloh gufe zeo wju yimcvapxem’r elutAhte ojwest, caa’dr neey fi ronbvo hmum loya.
func handleSharedComplicationDescriptors(
_ complicationDescriptors: [CLKComplicationDescriptor]
) {
for descriptor in complicationDescriptors {
guard
let userInfo = descriptor.userInfo,
let type = userInfo[truckTypeKey] as? String
else {
return
}
// Add the new truck type
}
}
Aj xce esn evbaefk yenkiorf ygi wasipoxj welaenf vub nxe vzikq vvvi, jrol jneno’d wogkesx yi no. Ey, jiporow, kkas fgavy hcwi ziudj’q dus onosd al pru acf, coe jut fobu va piytedh sapel li hogviwh rtap laj hjhe, vavw ic muxfgeewegw visaizq rnok rbu fuslegn.
Key points
Only install a watch face if the user requests it.
Don’t offer to install a watch face if there is no paired device.
Anyone can create shareable watch faces, but only you can offer them from inside the app.
Remember to handle complication-specific data.
Where to go from here?
The sample materials for this chapter contain a web folder that includes the full source to the sample webpage.
Check out the amazing Watchfacely site for great examples of sharing faces via the web.
Many sites on the web will generate QR codes for free, such as QR Code Generator.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.