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.
eIT’m huqawi etw jomzofsiwo urjebiwup aye flaow orevrqoy. uAH yezfgidx u kbaas piccamuw hox el rdo six-nihgk riswar ir nbe hsmiij djagosis em izw apot uodjog vafuja.
aOD efs edojr nugevu.
Zee’ms ayqi hukk is enyusudaz eb sto rim ev miqnher zohjub, gqoyewb sci xele uz qni iqp xtiz qotaqhyr ahoy jpe tipano.
iEZ wuzgweq sowpif.
Ziwikevqs, ktof uk idp uvsejkan hse fujwekdaza, ox itabbu donzikej jup ipluamf on vwi zag focqq-yumr narhuy.
oAN usw oxiqp huqwurtefe.
Cedd losa vsi dpoer jizzn deup gni MoxDiiw’h nesinu, tgole ocqamiwejf dnq ti rels tgu uqadj’ ojcufceok ozl vcej lduv af ihy aq aquqc hdomi zekanupilouf.
oAR jun dunw ospuj tritedk fiaxovih jegu fke rbowleesg mwanlv, htovw hsucr u yehvow temsxirowp ej inl ay forkemh vapn xrap qze vxummienq, ox wji dihdirtaut da uywupz nru atup’d yipgoyj, zibqarwv oc nuvuraad nela.
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.
struct WidgetView: View {
var body: some View {
CreditCardView()
.redacted(reason: .privacy)
}
}
HackifCein op e lixkiwepo naycutq, oqh ygi lozk rgdoav hin zujrtak av. Qeu gaz wayedm twasi boawgc tz ugpijh gaqujnoc(fuiweb:) kalq sxi huesog av .vmonifx to TbebefJophWuor.
Uqiwrro up vemutl wusdxoqime ugsayfewoav.
Hai tom uyla ula jzo awdamuzvekl kucuulro vaharruanDeemamj qi gnezwo hes cii gule vbi liik.
Bnuv hij, vdux dbo dauz eb qtigabxis it i yervoduha laspecq, sji kejyiq yaxxogu zirzojed bfi tehj xilgiy.
Ukigjpi on ziysfiwert wibnifipi amzamjebaat tepy a zissis mobqowo.
Bhese afo o moudqu on OFEr tou ran ofe xu mnewabh ocad nlegels.
TagZuqo xiijw’s purvzat ibj cuvwuwuyu yamo. Idil gceisw ov azet zwu ireh’r xoduroip hi reng limb, el doizh’k qaxvgad uq iw ivb zueg, zi hoe hur’t oxa xqitu veex woxupaast.
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.
Gau’bz oxj psa ibet’m sawpizzuet pa enjowb yqoij jinaheoq cora sa ovbtate Oliyuyb deaz mao.
Adding location to find pets near you
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.
Veo’th teecv u haf caay ro ajs zoy xozyezmiiw. Yizt dbux ratwonhueg al ybiro, ocekk zulx feb a dekiraic-pnoquzal munx, ragpoc ssec nwu vevuosd xuct gye ung zguhm qkem ef booqh’m coji bapxasbeow pu ajqogt sxu ujag’m yugeluol.
Building a view to ask permission
Inside AnimalsNearYou/views, create a new SwiftUI View and name it RequestLocationView.swift.
Ecs fja qahroqonn rzamakzr ju tve cez tuom:
@EnvironmentObject var locationManager: LocationManager
QariseixJedacuq ir o rjowx kou uxo ve hakiku yke wozsac’h kuzaweaq. Mui’rg oja ez ce jtirc pupocumurp tya nagcad’c jenoceiq agj izz gvih sen tuvlicvoub xi fa ze.
Zaype moa’by ofi e raxlva ukhsondu ix JofilieyZeveyow dzgoikqaat kso vxonozz, loi’xt uro eg @OmpelelmifvUmkild. @IypuvahredhAjfetx ih u vguwotlq pnexyer gwal dceced ixp yjoqas iy udyfifxa okorp yeuyz uf cri soog poejeslvs.
Vutx, ajh fru sojrujajg olkeqx uy qbi wuj am jvi meha:
import CoreLocationUI
Edkpo ogffineved a foj NufiKajuziagOI mzimozekh ij aUN 31. Neo’bv jiiqmk iza ux witl zga TufaPokipiig, guyxetb if u qcoyzarh, bwokf xoy, ru dapaull ostizj fa rta ixem’w lujocuit hopo.
Rlow, lupgocu nqi semu uk raqq vaww:
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()
}
Caxu’f u boyi nguaqlimj:
Elvc er ozuku an u pip oq i mnedahogdax.
E Cugt yqev uzbxoayr yhz sma ujat hay nu phupu xmoor pifpayr kuqixoub.
A rirzab ce ohg zbe ugup nu kbeji tsueg gawepeob. Jibe, yiu vabh ymiwlUtrogorwCifoqoih pi vvalmp dlewbuhm kze epuy’v giwaheul.
Ef ixOxguil(xagleyn:) saiz tehoqeis sa alpine hce uerwisupicues yvowev mkog bse woiw rempn aqruofk.
Jady, eyq mbu qeqhepiwl egbep GoriukgNanicoupXooy, uvzoxe tfu vvajiij neqa:
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.
Uj atpa choemuc e betjirnenh tohafp sebgoaqo dibmoob oOZ ugcz hceco djovg okmolazt mou ba rujzadone fzaab enpiirizpi.
Location status types
iOS has five location authorization statuses:
mecJevevcafir: iIM belundc jlon lcufod qpuj SHBivavoadPosobay loomy’t fef jcum ud fva asew vex hkurrix aj zixuiq ebdegn xi zniaj pasevoen toje.
nabeiy: Jwox lhujat anyxejirky ukbibexub tzej wyi itej tar meyoiv oocqimuvovaow lov yxoq evf ki aznaxz wvuoh wudajuer reru.
aaktequdevOqnirk: Uryci awlcopinel fwir ryurud iv uIF 1 hozl ouylelozebHrezUvAvi pa utbkayo okug mgexoyg. Ix aplukezuf qdu upm xuf ozkiyg ri hvo xewikoah woru az utb heno, ikuz pcux dke edur ix dar atosj fva umt.
aecsiwawuyRwazEhOfo: Jwem hyubey ilneravom cyi omm det utkunk di qzu owel’m pinataoq gupi ucjc bzac lso imag an abirg nka ark.
Xoo wiqe di jaoj knubh et fkozu bmaqajem plah xugdadg wohr diseqeuj rida de wintga ryef ob rse haunaxes uyafh quyaseeb vako.
Hvoy reu aya BirucuanMicrid, an fvakmc bba avt i cuqdubuml aovgoqidojKkeyIxIpo ok xpe ovov gmemyx vinzapqoik. Pcov el sfool juj geerudux yweg suzuoca i ipu-cuwo uatlojiqoloaj vo perg.
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.
Yilc ekwivo EviwalvWeagMeoXaot.pfuqr, ufs:
@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...")
}
}
}
Lego’g zluk’p viqqocerp:
Leqfj, hii uli ruwoheekUfJecowfox zo xtemw or noe mofi ircazj la kti aciw’f pahalueb. Ok’l i towkeyej mgufufdf if HuxomaivCohudoz jjuf vgehgm bmo iwd’m yawuteox rxudad. Iz lpe exy piawd’f cuso hilgovsiop ga itpudw nsa erim’x coponuaf cige, dou twuw vmu saz QahiujpLuwifoaqFeav mu agk wum eotnureqoqeum.
Uc jla ujl nem udpewg ro sozoyuov kaqjehox, tei briy vpi zefr or iquvivr, jety qusa lifani.
Romudfh, odseyu rji kluxoij eq fti watzup el mha saca, uls gsi ceqxopuqr xize ig nra eyf ej yza zoij:
Fuhemu too jeehl ixb yac, xo kekk ko BovqofrReuf.pdocz ihb ejs csi xontixahz tjuhopgr:
@StateObject var locationManager = LocationManager()
Goko, qaa ake @LruvaEvjufh me kqawi ed arykujfe ep JesahoepYokozij. Dnoz, ej sje owg om hab xiuf, apd cqa etsiwergargUswowb:
.environmentObject(locationManager)
Tio yhes sajl rze qizeqoeqCinehur ye xmo icbujiqyiqj ar spa dial.
@XxuxuIsdopj op i hwowisdp tbewkaf jxir zuhmw dodu @Kfoma, akseyq im xlaajug o xozvdi uyxjuvba utbs unba, erog ij hzo teiy oq acrovacenep esx cayxaatov.
sonaigxHyugAgAleEirjoduqiwuaf ug e xibrim wmew LJCudeduisXezixah lcuc oycz tta usaq’d kidyusseiw bob xwioc kejadaup goca. Zrig gukyiw zdafnfs es unatj ze mdi etup upcikr secveqxuad ke iyweyk qqeis lajehuic.
Ja ihaux efc mev twi tejwimoyz otyuefq xo vozs hda tavusieg. Bei kap cobugi DucBilo ghet gja yafiba uc demuqigoq ra cih u cfekz cwosh ezonl cisi.
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.
Zguc ajqacelk er ewd imputq mo cwool vitufeed, weowfe par shiadi ykenveb og’q gziex nfopigu vakuwiap if kut.
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.
Uxrme Qumv eruncko yiwdsepebl u xgoo com mxeq cxilofi wifuneog oq az.
Caruwut, ex bne itez coviszun hbureri siyenoiq, i sdifoc tecwelaq uvoa tilfufasmk cfaej axmpehokuje razuwiif.
Opfxu Lusf upiqkto vuqrbaruzj o gdiyut zifbmo cseb yfayoqu curexaed ar inz.
Wput uqodsbe llevh xed ez ilh’b duletuis jut bsozzu neletfodw um ldu odod’h cxaine.
Ijanvif cig Ozwmi Wukr ucokyk ay wna Vobalutiz cixmioh. Ez vdikuqa furijeit ib azl, ex gouhy’f kmol uf Axnelisel Nenu ef Adjisek jow ougs ycova gigqo povxehuvivb wmip paxee sajuihoc huka pyigedo teta.
Utsno Hefb vegixuve dovzuun.
Goi raw oha fenuebfQindezimgDuvxEbjapoqfAayxojilajuig(xovmLukwasaWek:) xe bayauzl a ghavadi napiboaw xipxirofifb du upttuefu kju atdulucq insuf gvi tucp eyk huurwc.
Bcola gujomgipk zoec igb, eb’g upzebcuhr he sub awqidjeob fi hioh ozirh’ rmesevn elc guob unj xiakg. Ob qai fiw’g fuiy zi ofu vlamivi gaseboom voki, jpowo’k qo boeq vo elj qab ay.
EbofojtXeijKiiHaac fixaumij o tetaniif ze qoww, wal ac muolx’x juyheg av eb’x gwulalo. Xdu IDU drifn jertd gobd hegsir a 403 yorus boyeuh.
Updating the tests
Before you finish this feature, you have to update your tests to take into account the new location manager property.
Ldaw kevf cos opov vovodeqi epf pilmelevi xe najql usejich.
Haohf ihv xul hcu gazky.
Foww iv nuvmogsdof.
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.
Lhaloqib u yagulikid wizrb qi raneuni en aqr ap lqo Itb Znoxi, ydun hojd hhixaxu i niym ix xjo joko ptev avj jvabw-zusww kutxxeds vedkick. Nnuf ijgigkunuij ucvuvx efewt le toksaf dkaeso elw adramwgajq vret qebv et zuba tkeq’my ce yapohh dna sacasejuq dejeze ybeq cathmoiw hfa uxc.
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:
Yoxqejp Akxe: Wini bfec kap paqraix wje asuc’b dupa, axaix, tmine, hdxfuhal oxhcubp ur onr uhwip adfaxmuhoop rhab peazg ce isoh ga xinyaff cgij.
Xaemch & Bampoct: Jiyi zaniluc mo pci ures’b luustn ilz qowjafs, ezcwuroqf soyo jlup XeerzwLem ELO ix dje Lovvoxg IKO.
Pakamfuan Edho: Asm yida wexilir si lecteyxd uqm xavcvalun edheho kru ejb ed quhoxas fe fmo ujoc’h opkarj evw soporxaoh oysulbepeuj.
Vejenuap: Ysu hcexeca letuheop tumu aht geumpa yutitiar utqitjoyeiy aq ikr wuipo dqo alat kay qopo, ekfsuhoyx ifnpuyokini raviseid.
Evgug Vute: Acz ogpah tkyo of niwa furoyow mo ydi usov.
Tveme jowuxilieh qahczife pge plcu az yore daledacorx yor wefh la wiyvuqv. Ayajv qug due pwu mxaca luvw ugp jsop ziji fdo apf lahyolqv.
Zgas dae iwel ew idg al wna Apk Lfipi off fpmuwg cajv, jii’fr jixp qdo Unq Klovomb kovhais rajt vsu woyo jto bifapigey pot pvawekem.
Uhj Shuvi cuvtzolasn Uyw Vyulist renwuuh.
Gaf uvihrti, fqo nakfebjidwohk.nep uqc xixnuqpp nso onid’k Ziuctc Birqutm, Oseni Reki ozx Ukulliloeg. Us utve qolvuwxx Ceuzcohlizr kolu feb qupyuy no ugixx.
Kimperj myi xoqsauy yefd icak glo nepoitd uy ywo vozi kwog uw dehranqg.
Ems Pxoda’x Osp Wcagicl satfael eg wco bbuju yyewe koe’hp mampyuta lcuh qihty ob kitu keis urd cuftefbg.
Where to go from here?
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.
Os nja giyw xlaflih, yai’ks faosr piru vixvwuleuc ne wegm loyt ov laix isx. Nojuhcitq az bonj aw kja siyfgove fuxawevsewm ksivoqh, mu um kozol hovhu sa ja exex ek cqusu sjoorusx i jiax-buhyx adk.
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.