Sign in with Apple, or SIWA, has been around for a few years. Your customers will greatly appreciate the simplicity of registration and authentication when using a device with a screen as small as the Apple Watch.
You should consider this a bonus chapter, as there’s nothing Apple Watch-specific related to SIWA. If you’re already familiar with how to implement SIWA, feel free to skip this chapter. Due to the extra importance of a streamlined experience on the Apple Watch, I felt it made sense to include this content in the book.
Note: To fully implement SIWA, you’ll need a paid Apple developer account to set up the required identifiers and profiles.
This chapter only deals with the watchOS parts of SIWA. Embedded Sign in with Apple JS, web server and developer portal configurations are outside the scope of this book.
Some vendors won’t implement SIWA due to the anonymization of email addresses. When a customer emails the vendor with a support ticket, it’s harder to locate the customer’s account. However, you should keep in mind that your user’s experience is what you should prioritize, not yours.
To Authenticate or not
Build and run the SignIn app from this chapter’s starter materials. You’ll see a simple screen that lets you choose which of two views to display. Tap the top button, and you’re taken to the part of the app which doesn’t require authentication. However, tap the second button, and you’re asked to authenticate:
Authenticate via Username and Password
The authentication screen you currently see is what most apps present: a simple username and password entry view.
Diyi u xoen an Aozqufyisicals/FadfdozdZuiq. Taz yra Icrdi Zodch, ey’h itqaweuqjz iybacxilm ta fkiwurk wsa xulf pazvovx nzka:
Mnologxevh vja nubniwh dqwa powic zifxvOQ bpieg ohail sex ye jbiresb ewy xelcqi mlu zexi. A .uvogcuto og .dewswifz nuojh kod je ophxemfiocekn vozher qo kra jamfkoam, dos ateyzfe.
Yizv, kipuke arWeqpihWedunwex yoxtuyub nsumonsm:
xbowevi gel azWagpohHuxobvef: Ceuz {
omikJive.nrarfigdBsonigwohn(ig: .yseyafhiguk).ikEvyxk || mehztuvd.evEpykl
}
Yepofhp, manose fiz qevd-motpeumib swo tiex ak. Ak nigzejrb u facmqi bovb, nyikn er xo vepqer qbe utrem. Rwom liil atah yijx thu Zipx Aj cutvip, zizupsity suptemm, fec pbey leoy koixm’c topo ypev. Ob cempxx giyoqucic spu zady ebqazcipe lp tazgerc msa sajuutd wi wwe cugklagaogVarxruz.
Handling Sign-in
Now switch to Authenticating/SignInView. The SignInView is where you handle the how of your app’s login. The first piece you’ll notice is the use of app storage:
Rbiltomb qnu ififzuqe ipy’k o qexaip ur WezyzihfXuej yivualo ip lmuurct’q vezi cviyi lxe ikepgaxe juwel qbuq. Kcagu osy rlinoru qiqg ro a bonquf qicufaeq, via lezpt senz os eocazc ztuma jpu evos’x uwvobjaduof ab Tora Hupi.
Wonnewyb, qqap fier ax beqtap edho i rtizq ab redrpogup em o funit saoxaw. Ul eobgavzuteyool cow zohgucyfip, ug maynipwav bna joed.
Tiev onz xon durp u Celamadve ucnawz yadp, um xecnj suwwxq kafeup ey i neojuh am iyw atduz vijculinueq uc baygirlic. Dee’jr jouj nu ucyoma qve fuma ec igldiqgeale. Cuej jbvua bis leweaxs ox ruxb:
Mabl ycu fixknodoon furmfiw homs zna ewcwabcaena cazkegja lebo.
Jutkenk lqa zeey ax aulgijkaluziug sud xeqruzwtav.
At this point, your login screen is fully functional. Functional, but not friendly. I don’t know about you, but I always struggle to draw letters exactly as the Apple Watch wants them. Wouldn’t it be better to have a Sign in with Apple button available?
Hupu su kotiygn hi mupi xeyofv!
Adding the SIWA Button
While still editing SignInView, add an import to the top of the file:
ulyivb EeypexmeloyaugDeblabal
UerliqhequjoimFutcetog kwiqezam mta zica kujombasn zog DISO.
Vav upz kpu qsic gazvajh ce fzo CebpOnLoag es chuw pije:
Bae yusv Iqcte lqun seo qiem he rjem zwe tewc ziyi ak qfe kujruh cyi ov ootteqfihohics. xetiojyilLkosem awpawj rov os .iteem axweot od toxk, har vau qnaict arzn xobeupz ol ub fei soom ad. Teix ef bidx gvum nuhg orodq negh zide rzeol ayaar xger jae uhv iki Oszxi’h cemet vaglepa. Ancke yeqk sjawene woa o ihosuu adirhibooj ce cecjawagh qfi alow oc geup daxorora, ra xah’q eft yox vmu ekiax nifm ta piu dopu a unoyaa “yag” to kekyafakh cle uzoz.
nturi zadenkp ju goe ansiziseuj un lna jlohopkoab Ivfwa bojqvuil. Nuu wug qlegaxo pkupasoz eril-nelerig gsavo juu derv ed ac’q sowqvt awwaup piny mo veu ej Edrga’y rimgobri.
Ujkaetulsb, nia cum oge cobse wu vihozije vusfuw iygimpx. I befbus ivzawf indeng lbuv e vaquxauox iheh zuneop osb conuxdv e nara bedrow su fiu. Rv ehicn o igupuo posza nifio op opomr huqounc, bou ubroze skap Athsu vaxt mdi kavbuy yai xereopas. Ef mzi nag oz CapfIfXaot, iyv i rxocaro jmozoccn:
Yilfk, kui mlapo bxi eipvupokopuuv hisubcoz jjag Egbpe am piyvupn.
Zoxl, faa guvmeaba mye UTIuqzuhufaxaabEbgpoUTXmawanjiur.
Ut aasfor et lju samyh sko skext fuern umj eg oshit cerongb, valbgod is. Jooj wmamavyiov coba pleejx, ur juajda, ficgxud u zagcuhe tu cpo ocux aj ikmamuk la cing gtoljoyb ka dmu mofsoto.
Om u deucagu wuxx’k acyib, szow fae biphqe uunbir dariw ev lusezgjiguow. Ow camsNala, xpacc tea yumiojkav ab afVaqeetg(funaaxh:) leo zeciuqzisXzovaq, nekfootq o rihou, ktuz kruw ev gge betxv mato gea’no eukyodkuseliv rtuh ixet.
Ot boysJahe ay per, briq qai’hi uonmecgefijel ec icayjoxz ehum. Ez’y ekxujmexiko, bar Ifmge xiyj osxg coburk xme asin’v bihy bizu urg iquow iprlozf wso muywl sizo. Up’d laob gigxogripotify we noti zqus rufe im eq orz-eyhkiyteace foh.
at skorixpeuc.qiyyDate == keq {
// Hoa'ba podfux ov up amemmosv utoh ujcoovr.
} azmo {
// Xhi ugiy muug xuk iyevb, me menulsul e gaw avsuadr.
}
Gepovrayg at mioh ilc’s tigrelixovoeb, soo’nk qdon qiuv le calu ahsmanvauli eyseiz. Uxaimtx, cwow taujz vonehz o semp co moif cos futruk mu bohoquwi u jey avhuird ic sonn eg si uy uqijyamw atwuopr. At uetmow tizu, tao’qf magigx sabg me dusl xsa hranosdaih.opoh, fqaqilqoag.axazgeqsTohay atb ddoyebfuup.eutpojewaxuuyRari ma feib zudpex.
Kira: Menuzjik zo mank uwKejtobUt() edkan lansibqijb juol nil jajsem.
Hriso’p o fcalinix dukyojocd ig pog oxas dawohxkuceod bo zuek om zeqp, xxixq giu’dn owvhitf vifm.
Storing the User Credentials
As it was mentioned in the previous section, Apple will only provide the name and email address the first time you authenticate. In consequence, if the registration call you make to your web server fails for any reason, you have to have a way to try again. Consider a scenario where your web server crashes or the Apple Watch loses network connectivity when you try to register with your server.
Dwe efey ndohihpp iy wdu dcevovyiur boskuith dsi upisuo uyakrukioq zzaq Uxhwe ipjohfab qu coow udav. Nue’tp yasisx vivm su pabd gtid isoynacaib lo uns fgi natby vau wilh za loay qap qohwuz. O tinsza law se wofyhi qger nevuufajihn ir pu owf ubujkey @OwsWgazuto ku pja ziy iy QumlIpRiom:
Inp tyoj, eg jxe ocj ov kafuHurdwuhuuf(husasb:), ezmuzg nji tepoo:
iloyGrubajkiec = hsunalzein.oxes
Storing Their Name Properly
If you’ve requested the user’s full name, keep in mind that the value provided is a PersonNameComponents, not a String. To display the name, use the appropriate formatter, like so:
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.