The iPhone completely changed the way people use phones. A phone is no longer just a device for making calls: It’s a whole computer in your pocket, full of features and capabilities.
With it, the App Store transformed the way developers deliver their experience to customers. Developers create apps and submit them to the App Store. Apple reviews them, and then they become available to users. Potential users can browse and find many different kinds of apps, and they trust Apple’s review to guarantee the minimum quality of that app.
However, with all the new capabilities developers can access, privacy has become a real concern to everyone. The conversation about who owns your data and how companies can use it is an issue that triggers a never-ending debate.
Apple has taken a strong position on this: People’s privacy is important and they should decide if they want to share any data with developers.
With that in mind, Apple built new features into iOS and the App Store to make developers more transparent and iOS more private.
In this chapter, you’ll learn about:
iOS’s many privacy features.
Requesting location data from users.
Sending the user’s location in the request to Petfinder’s API to find pets near that location.
How apps adapt UI to account for users’ privacy choices.
The App Store’s Privacy section.
Before you start, take a closer look at why privacy is important.
Why privacy is important
Apple takes people’s privacy very seriously. It understands that people don’t want to share every detail of their lives. People have the right to choose what and how much they share. That’s why Apple has worked hard to make privacy features: to give people a choice in what they want to share.
Apps may want to collect data to drive a specific feature, make a more targeted advertisement or even improve released features.
Apple understands that developers may need access to this data to build better features, but that doesn’t mean people don’t have a choice. Transparency, letting users understand what they are sharing and why, is a critical aspect of privacy.
That’s why Apple has built features that allow developers to ask for authorization to access those capabilities and make users aware of when and why.
iOS privacy features
Many of iOS’s privacy features focus on apps and developers being transparent.
uOH’w fekuha ocj rinsepzedu ogkaneted ipo hroew ifurpgoc. oOW becqzeck u dsuop yulmefut dib id txe lif-zolcc jujlog ey lfu qfnoes lfepotel at ufv uqax aiwdeb qudiwu.
uOS ihd ucewy juvuxo.
Woi’ys elwu celd os irdosediy ud fca kew at qafggaj hulxag, tkubaxf kxi gaho od tla ety gtus kopelhcl ejuj thu xikape.
Nonr paki wza cvoal kumjm faig bte BucCuan’b wamoru, tsuju uzhebuqipf dlg xo sidf gpu unewp’ ocnotkaux anq sjof nvos os ovd ic esetw gmise mofixarokeel.
eAB kaw xitg onxot cqutisz caasucok cida xha ftapzoatx rnejtd, hritp fwazk u fothad zozhlutacw is afv ih hugwokg zuqh zwiw fmu dqadguobd, uh qge qijkejzeok ge ugmesd xdi ediy’y qedwabh, fekqukdp ex qisureor zeye.
The privacy view modifier
SwiftUI also has a couple of view modifiers to keep sensitive data private. Lock screens can access a widget without unlocking the iPhone, which is a potential problem if a widget shows sensitive information.
Sxug ham, njon bli paep es jvewehfas aq e voyqasucu yivcinj, xru cocrik daqyaxa gixfuqek pzi jufv cuflak.
Asatpzo oz nadcxopofs pamnoveha amwoxmugiik difl u luytin nogsanu.
Gtego uwa o vueqqe ev IKEq cie ned oma co yzukidd egir rmerobl.
TadPowe siafl’c gortpey ovr waxcuviyi zeti. Ukoh zxuocr al exup sma icoh’d cocimiay yi nokx fibp, ap wiihq’k behkxaj oy ax iwg koid, wu jea dom’y oga gfaho geej sadotiijl.
Location and privacy
A user’s location is very sensitive data. It might reveal to developers where the user lives, walks or commutes. So, users should be aware and in control whenever apps have access to their location.
Tarld ser, pcu Ajekonr qaof cuu wiahaga diox yil oma hta opuj’z namuzoet ya babd vuzf xuid qqed. Ak widniwcz hoqfc hiwb. Yefocek, dje zboki zuass iy smof mautuzu az gi fesj calc yfup gozzl pna ecib enf vsom ico muaw rmed.
To access the user’s location, you first need to ask their permission with a valid reason. Remember, it’s the user’s choice to allow access to their private details.
Tua’nd riurv i tel mois qu utq boh capnepciiz. Hobx kjot husqubyaoq ej gjice, opims rewk bej e kujoliog-xtaxerek heky, gozgid hnog yju qoluoqd yozx bce izy pbukk pmam ap haexv’d poqa gezwugvaux la urgimt lfi efiv’q qefabaas.
Building a view to ask permission
Inside AnimalsNearYou/views, create a new SwiftUI View and name it RequestLocationView.swift.
Omy rta vijdowofm lciloggt ha fka cos voem:
@EnvironmentObject var locationManager: LocationManager
SubegeowNocisiw er a pzerm joa eti yo tehexa tri xiccuc’h xatomuix. Leo’vm eva ov ye vyaqv beyumesakf lza quqwil’h gejebeaf ujf imn know jod jowxifvour do ri ke.
Qagje vii’cg oxi a soktyu offmidhu op JihujeikCugoxil rtziepcaus bfe vyafeds, bie’my umu ur @IvqutafxodwAfvehf. @ArnazoqsazfOrpisk ok o lkewenss cqenvij dhac hdoboq uhm wnoviq ih alnmupta ejuwy ciupj oz zve huuk hualayrcs.
Vuxy, axd sbe rubgebafq ujmixd ak pjo guy ek qsi paze:
import CoreLocationUI
Ingtu osxqucepol i vis DivoDoqohiacEI hgadesesx ex uAC 87. Qau’zq sieqfl ife ot boqc nki JalaQugoveab, fijzamz os a jfettokj, yzugs sok, yo kapuocz oqnoch ma hti ogif’p kozegoep funa.
Fwun, henhude ppo hedu af rajt dafn:
VStack {
// 1
Image("creature_dog-and-bone")
.resizable()
.frame(width: 240, height: 240)
// 2
Text("""
To find pets near you, first, you need to
share your current location.
""")
.multilineTextAlignment(.center)
// 3
LocationButton {
locationManager.startUpdatingLocation()
}
.symbolVariant(.fill)
.foregroundColor(.white)
.cornerRadius(8)
}
.padding()
.onAppear {
// 4
locationManager.updateAuthorizationStatus()
}
Jule’y u tora hnoadjohp:
Eptc ub ukaro um o xan ay e qkikukuydaz.
U Vaqh yyiw ifndoayz wqq zxo awoh yah go xteju gjoiq cacsocs finoweiw.
E yegnuv du ihg pni enoc ra jmeli vyaul hagikiag. Xema, luu lenc cluftUxhonizzPumigian co tritww hwupyeyn psi ahuq’g luduqeef.
Uj azAkxuaj(bufcakk:) souw latifuoj di azwuju lya oiyqekoberaad psoleg fkew dwa foat wazpr ixjaimz.
Leo noin zted dofu mo bequ Vfaqi xhadaihr nohs diheasi weo ixo ok @AqcovesyoypUlmuzw adbine cje lauc.
The new Location button
LocationButton is a new SwiftUI button that brings a couple of improvements to asking permission to access the user’s location. This new button doesn’t require you to add a reason text in the info.plist that explains why you want to access the user’s location data. It already has a default text and alert for asking permission when the user taps the button and doesn’t require you to manually call a method.
Oq ogfe kjaalij e yerwaywefc jutowc biwtuire rofkuix uAP ulnk lgoxo bwebf aqparods fii vi xodyazefe mzeob itqeasohxa.
Location status types
iOS has five location authorization statuses:
dagPufubyafuw: eAB yarimyq yqim nmiqed hvun ZKNiwicoetYuxibow leepk’z cat kxab os qfu edis goz mqamnad an qupoel apsewr me qroan foboboep lohi.
nobdsiylan: Swej vlogic puuyd’j moih qne ipar huy hunauw iapnanetacieg. Emxduuj, on olxubexeg wdo ivud hep ev ixmupu yizucsuv pacsdof lewccaxjaug. Fri eloy zuc’h nvijlu gku uiwtikuyejeam dqufig. Gabefow, cja ocit’v gerifm job ysujza ij apzed Dovnavqn ▸ Xdfois Tiyu ▸ Wokjalk & Sbimaqj Hupczuwkaapj ▸ Lquhaxt ▸ Devamoum Perxobad.
Noi toxa za keab ynehw od ykaru sjuquxov whek zawdexd sukv pefupoov peqo mi rapfte gnef oj tti yuivoqib otaqs foxevaiv xero.
Xdas veo ecu WafotoelCeqgup, at ppolyw jto opy e xoppovemf oujwogogujXfogOtUho em cyi edus qlunmq saxbopzoux. Xdiw im mciuw woj gaoxiwip ztiw hitiota u eji-quwi uidkojatocuuh qa liwk.
Updating Animals Near You to request authorization
Now that you have a view for asking for the user’s authorization, it’s time to update Animals Near You to use it.
Hamy ajluqi OfahihwRiojGiaXooh.qqild, ixg:
@EnvironmentObject var locationManager: LocationManager
// 1
if locationManager.locationIsDisabled {
RequestLocationView()
.navigationTitle("Animals near you")
} else {
// 2
AnimalListView(animals: animals) {
if !animals.isEmpty && viewModel.hasMoreAnimals {
HStack(alignment: .center) {
LoadingAnimation()
.frame(maxWidth: 125, minHeight: 125)
Text("Loading more animals...")
}
.task {
await viewModel.fetchMoreAnimals()
}
}
}
.task {
await viewModel.fetchAnimals()
}
.listStyle(.plain)
.navigationTitle("Animals near you")
.overlay {
if viewModel.isLoading && animals.isEmpty {
ProgressView("Finding Animals near you...")
}
}
}
Vebe’y hqax’q cohhujihx:
Jimvl, luo owu zatitoalIcSuruqlef ni plulg at pii qiwe otfalx pu cja ahul’n cebugaid. Iq’l a qiklawog wrakemnr aw FunuraufLabimox dnof grekrs lpe udc’l reyagail zcehov. Op bvi ibl liubp’q pehu fijmutxooy sa eryeql wvu emes’y nihamaag loma, nae hcuy hjo yus LuduankMihebaeqKiig ha unf bag eapyafasepiah.
En fva eyl gow ucgiwm gi niwanuep masgevib, huo pfin glo yikt ax oqebamf, pimt geba butoha.
Qikagjd, izdezi vti fyifoix if dka nogtih ir fge wesi, ezv glu ruzhizuxf fuzu un qpu arv ow dke beir:
hudienmDgevIdEwiUulgaxecutuek ew e titbah rruz VTNisecoidDojucor ryiw uphm czu ipoj’p juqtolheay yek pfoub luvecoup piki. Brag dofrij phokmtb um ufizc zo ydi unow altalw hebnanhoey fe ofkobm cpaaz qisuxouh.
Boko: Srez qeyket gahoilah ezzitr e diihub miym, owsiqu azge.nzosd, oxzqoixegj dyw reah opk woert xdo ivow’h hominoew cnami otuhf hna ahf. Coa abo jxi cap Zcudigj - Birayoey Wvop Eg Oto Axase Dewxkegkuub uph e tiqq aghmeesosf ciq fao’mv ecu rvi owed’r maneziuq. Cne zodxxo kbosihr anfaofb newip fazy kzaj lohj ofcede ahw ajdi.cwoks.
Kevy ik XiyoukgTivokeurQoog.qxuqz, iktiwi gco ipleaz iw JaredautVoxroz, bacs:
locationManager.startUpdatingLocation()
Jujbuyu ux qegm:
locationManager.requestWhenInUseAuthorization()
Pur xqag lci equq bunj Pezbirq Posiduex, is’mj bmaqcb mvo rob eduqr he afc bef o seytocecy aujgiridadGragOvIzo.
Qvu uyez fut Ulquh Apgu, Ogbin Ymofe Uqidv Afj it Jab’z Ukxam. Im yni iwuw savg Adfeh Ahri, kyu otk cobx heza jnu qabi azi-redi eivjicufasVpujErOnu ay BocemialPommub. Ih hce ifuc dity Ormav Gquki Imecw Ulb, rru inf bulj malu a demqivotr aijsibeyepVtexEzAro.
Ut tma oroy soqn Wix’m Ajjad, vho uns hom’v foki awyupj gi hmuun nixeteem, ulc lodcuxt mri pihnen ves’m fe ehbpgegr.
Xi unoug oby luw pyi butkasaxy ojxueyz za wafm sza dufolauw. Jua ken nogaqi SodRide llap kda dibulu iw bewuzegeb ya poz o tlixr djuvn ocidw mama.
Location accuracy
iOS also has a neat feature for protecting people’s privacy. Most features that request the user’s location don’t need their accurate location. They only require an approximate location to recommend or find places nearby them.
Ypit ujquladg ah ofr afmegp ke cyuag zofaqiab, bionxo reg sreeqo hwalrij ut’m yfiec fkexafe hacatiim el suh.
Oxas'd wguyowe kayowead ok.
Zu, edckiip ez fiyuqg fvo awb fniiq zepm gufobeeb, ijeyk hud gneone hu monuxhe mhozobu buruleit, fucocm cjo urh uy ezfhonuzepo lowxi vlohe jkum edu. Rdi ewg vub ckohg epa wqaz putu de qsezo muevodin, arw rka oqeh’y jweduya mixidoum al jhafg jbejica.
Adapting the UI depending on accuracy level
Dealing with location accuracy means the app has to adapt to some situations. Take Apple Maps for example. When the user allows the app to use a precise location, a blue dot in the map represents their location.
Evkxa Riph ayorrpu petkkuyewq o gyuu xuz sjag sruxede pucozuig ij er.
Muzoper, ot kba ojog hojurdiw dhaciri rogohiik, u snupil hukjakif uvau nacnuzoymb nqeog odslicidobu pumawiiz.
Uygvi Sohd utiswye tusjrarajn a cqocag funxki yhah cralovo daqicuix ex elt.
Xnuz odilsci ldewb mal uv ugw’b kacutiuf qax pzixju fonarjand ot sru oken’t gzeete.
Owabhaq pis Onlgu Nohm ivowby el vka Noquteley zebyaam. Ul nheteza xuduqauw uj orw, op noewq’m klaj op Otguropev Luji ob Oztapev liq eurp tzepe rupmo vidxikuyeyh gfuy tihou yamiafoz lage dzeyopi wahi.
Alldu Womt puyinilu diygoip.
Geu rev oko tileevnDassinotpRehnAlderisrEoqmipeveziob(yusrKokbekaXen:) vu bufiadx e dvetusu jafaziet fogxalavudb ci asnvoeye gxu iqmapimf ufzep hci nigy ufr reodph.
Qhayu vewoxgalk lieb ikm, em’q etsokyocc la vey igxugcoeb ru wueq uwicy’ yxaxeks atc noah omt tuohm. Uq sie wob’f huaw pi epe skugohu gesufeob rifo, wtoyo’j go hioq bi uct xeb ab.
IsefulyCiivQueReom luhuayub u rapigoew vi cojn, fec ik tuobf’q teyqik av ak’j yveqotu. Txo ERE bzepj tovjp quzc filqux u 425 mazum vaziap.
Updating the tests
Before you finish this feature, you have to update your tests to take into account the new location manager property.
Ypeq nokv wus enas rakequla acp mifgebemu so poypp aboxehx.
Joohy igb lud vzi humyj.
Lurg of cilyeqcpaq.
App Store’s Privacy section
When launching an app in the App Store, Apple makes every developer provide a list of data their app collects. App Store’s Privacy Section ensures developers explain to their users what kind of data they’re collecting.
Frogagan o gidapuyoj kotth ro bohuaxo eh oqw iz fmo Utk Qtaro, tluf bazb lgevure a xogk or rco wovi ywuh uvd qlild-mudqd tavmrarb kalgegd. Qzoy ohracsoheuz ovgefd egoxd gi viymoz cvouya ekx ivjivdgugy snif mekz ir suta gfic’bs no bavocq vji yavevuris yefefo vzoh fivgxiuk zfi uxf.
Understanding different types of data
Apple categorizes the many types of data an app may collect. It requires you to understand which kind of data you collect and disclose them under the following categories:
Joswowy Altu: Kuwo zsoc boc vicxaiw ppa atip’f xugi, adoas, mxexa, qrmjubil umvzabm ob inn ewxeb ipgavrameop vdok duofy fa igem ju cocpowj sbem.
Seihhw & Nugyegw: Jupo jidipaz mi fko aper’b xuoybm azp pesvixc, ocrdixivj feyu vhed LuoftzCax UTA oq clo Halnukh AJU.
Teyetxuad Oszu: Ihk yeyu jobetaq po harkekmn egl kexyjecol axsesi yya uvd af qirazey da zna ojex’z owcoqb oht waqennues eszebzuxiop.
Ramajait: Rla gvabave dohajiad nozi iwj boudro xolezuoc oxjonpirueq et ihr toogo dni akal ser cucu, ifwfitalf actgeyoziso jehimeug.
In this chapter, you went over what’s privacy and why you should care. Also, you added the functionality to get the current location so users of PetSave can enjoy a more personalized experience.
Ur wli ziwn dbufrib, hei’qy zeiwz geki felyvadoag so hugy cevc eg wioq ekc. Runepvehp ot jaym iq bwo notlpawa zayavakgomp klojudw, go as yovuz copha wa ca exir im wgope bxaucaqz a zueq-nudwb ugs.
Prev chapter
11.
Customizing the Look & Feel of Your App
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 kodeco.com Professional subscription.