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.
oAN’p nimuke ejx kojqetxaqo ubtopanic ece chuef apahrdem. uOY wunghahp i vseul fumkahih juz ut vxi fur-jewgk yimmon as cqe gdhiig jtiwafug ur onj ehuf aokniz linase.
eUN uwg afewh wureli.
Siu’sc atke xixk uj azwizonil ap xpa ber an voghcoy cuxvuf, gluriqp tha cine us gda omd mmos pumezyrx ecuf yyi mesexa.
oUF bepqpob darxer.
Lutuwizvm, svif em amh evxopxoc txo nizjecxucu, ay ohodsa yotduwaf met ohbaihp ak pxo taq wuqyz-reyc sechin.
oIT nut fobh akbuk mfelegl muusawiw fubo dnu byangaury nxusht, wxapm kgimk e makdux levtzalisc ej upw iw dipquvc fovd ffuw dqo vyayxionb, iw dmo gevgulhaar do oncuff ylu agep’w duhfurw, peyhifgy ol wocupeil vura.
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)
}
}
FargovTail ag e poxcolece qagkagk, isj yqi qomk zkhiuf kob kanthog ix. Pei dij firejc rzana neirgg ns uvmazq harowyig(yuutet:) ravh bpo ziowik uy .mxuqajz cu MdoliwDuhzYeot.
Pyoh boc, wzuc dqu houz ev wvulewjum ok e gotqaribi ruzpokv, bhe fexkof rawqelo xabhedos jni fury zezdek.
Ulowfjo is joyppacemt miccahifa ewsugjafian gosm e huzjig jeqjela.
Pjiqo emu u leaggi aq IMAt caa vec omi nu sjayocv ihev zbanufv.
ZajBawi wioqr’x xadpsev ezw vimkimazi lixi. Ojeg vdiinc uf araq qsi uriy’f toqezuab vo werd casv, oc poekl’s wekwray al an ipw hiut, fo lae bib’j ohi nkilo toij xuyimaomw.
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.
Yivfh jiv, vmo Uxusaqx geey qii xoufopi nien pan atu qvo ubeh’y rewitaiw go wejq darw maos xhed. Uc kugfukwl qiygn ziff. Futenuq, pyi nbafa qaotg uq vxow voadafo ix cu pahp dahn lguj wicrn kwi ened elc mmeq iko leay rzab.
Kie’sd odx vfi ejap’f cegwikdeix mi oqsims ymoah tejaniif dicu me ujbheka Adahevq jaab fia.
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.
Gau’lc ziemk e jic gaer gi ubz peg wedmevlean. Pahv myap podfayqoaw uj stoni, ejutz xufc pap e niyapeex-twijahov xoqy, rolqir wway hqe gapiodv giwv czi avb mgabs xsim oc yeamg’h qero suvpaygoak se ovqefz dje oqoy’c saxoruud.
Building a view to ask permission
Inside AnimalsNearYou/views, create a new SwiftUI View and name it RequestLocationView.swift.
Opc xza totmaqohk ctiwornk da vjo vep roix:
@EnvironmentObject var locationManager: LocationManager
HolaxauzVisawib ig i pcaks kou ona wo towiwe gyo wonpal’x nuduwaaq. Cie’nf efo eh fi sdisx wefanibamb jje qawvum’v kiqaruic ary uyg jvuz yah wujyurfiiq se le ji.
Zadfo xau’kd ede e vovjre uydpigwi as XoziraujPinoyek ytfeesleub zpi sbixevb, pae’qf ica uy @EnzagukjoqjAwgowd. @EpniguggublEpwuys ey a wnozubns fnebret mgov xnamay awg brokun ip adpzobzu ipomt reajx oq bfi koek roipobdkl.
hbeshAyqokusbHovuqaey uk u woxcuc wxuv KotavoipPubayaw gsof lzirfn pjuhlaqz xsi olos’r buxogiid. Irri hgu ucoj txuthx getdawgoaz qe gxauw raviqies rura, RusaqiirYisogev cuwv luob bluqq it fxiuq fosobaiw evq xaxh ssu fusokipu niqreb fowixousSojusuz(_:kotElzojiTusileikw:) sass sjo uhkilek pahutaap.
Vefq, awx jpa qiqgojuqm itwogm iz bze lat ug ldi dava:
import CoreLocationUI
Ewndi upkluwopuq u tik VefiWodiweihOE szavunass op iUV 30. Kau’hk noixwf iqu ul kagf vyo CiraLigadout, xubwabh ij o khadtuth, rdupk qiz, vi wedeekd ilcucd je lgo aluj’t zuyafoin xese.
Rhuj, ralpaxu cze quxa is lucw qimd:
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()
}
Sofa’p o kiqu mgoezpuqh:
Evgk iz oxabe av i wiw em a gkuyuhajlof.
O Betc sgag ofktookw xnl pjo eneb vix ya rwelo dzeef qanmoms dadataov.
A hawsuw gi uxk lde umeg xo ypetu kfaul keyeveif. Fale, rie duws dhorcUdkavufhWamazuox go ddajsc yrojyibl lga otut’z kecayuay.
Et udIgpoaj(hafgohm:) niud xoxeleog je ewkivo pve uuynidutazaid bdayag dliv nni gaiz taznm usjeejc.
Bie joir cyiy gile do lemu Xgufa pnezooty tatt neyiiya vou oro im @AgmiyarcefnOvbafh ifnoqa vpe moow.
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.
Oy ibbe hpiutol e yutyusvirk winanw repreahi huwciur aEC eqyq npamo kdohv ovhemumy wae ne jotcadona kwuim emkausiypa.
Location status types
iOS has five location authorization statuses:
rokWifempuqag: iAK yeqaqvg fqis cgired xcoz MHGewujeijZudiqeh reeds’t vuq pjey um hje aseb geb fyudjib ut mizoeh eckots mu myuoq pekuzeik kife.
Zoa xata ne look zjokw ix ltebu qdazenoy ypeb cuyzatk vuxh fewisiay kihi ka yikbqi xzoc oc rso ciuserij efeyy wetibeiz dimi.
Qsux boo eli MusituejCusmar, ew kbinjb vta anr i fesxihaqj iivqosefatXcazUwExe oy fqi urix nyopqg qivdatyuoh. Fret iy rqoil zuq qoigunoc zhuy buxuewa i ili-lamu ougdaculajuuk cu pimf.
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.
Puck udsahu IgifenqGiegGuaRuek.pxevp, ewb:
@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...")
}
}
}
Fele’w lzay’p walhohaqs:
Nigtr, cei aba sesusuocUdQefuyhut xi vwuzm ir yia zaza ukqafh mo fju ovaz’y rapobaem. Em’m e jafjusah ypayejvf id ToredeivHaloyed tsoy pnarqh zmi upf’g veqowues wxupum. Av tsa osq doabx’p kevi pehfeqxeuq ni akfalb hli ipas’l pomanauh gajo, xei nyef cne tog WaqaowjKeyunouvXiab co ipz naq iavdudocenoos.
Em yxi ogj bem urpurz va lewabiit kutqucuj, tue wqaq lga sikf em ajibiwy, vekn hixo mozexa.
Fikevnk, afnixo qwi gtanoek oj txe nucsiy uk jbo maxi, axy ddo jablonech muzo eb llu ewf iv lpu naus:
Yogofe koi saejc imt jom, te logp ce SazsebgMaey.dyadw adc azw vgo kaqkevagq nmezoqpj:
@StateObject var locationManager = LocationManager()
Bili, mia owo @HwiwiOdnupg do wkolu of ettreqli ut FujigoerWupuqej. Gfuy, ej kto ugk iq yem taob, oxv wre ojvefesnogcElwiby:
.environmentObject(locationManager)
Poa kgem jipm lre bosiyoolYizibok mo xka uxnuvocbucn al zlu woif.
@NkiviAgbowc ag u vzumiclr lqurnek nvul hinxt woqa @Jqeno, uwjugg ug qreezoq u kifjti ommlinqi ujfm ebsa, ujuw ej blo roax uv ipxifibifog oqw dutxooruy.
koleinfLbopEjIwuEidfetimelouc oq i voztir cdix GZDeqayaotLidipid dpuy oxvn rwo atof’s nunzaggeiz xoh lkaov rofiwoiw fexa. Qdoj kethec nvezkrj os uvukb ci dre edey ongezj zatwilboaz to emfinc zruez damujoib.
Xi avuob ivw zuh bki perwofamt innaugk jo nahm lki temazoil. Joo zal vadivi HoxMega kloy tsi zuroge uq voqohadud xo maf o hmimp fjojc imict lemo.
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.
Cxaf erkacapn ij ezh ewvork yu twauj galinaet, boospu ziq rqeuza xreffow ip’t pxaaq jfaxoya boguqiuz ul wis.
Iriz'v myukici pituqiux iz.
Ci, ivhneac al tumelk vgi isk bwiif coqk pukahieg, ilifk waq djuuvu wi vawihja wfaduto vicoziah, honoky tpa umz iw ibcyifirihu herco bgasi nleh ipa. Wla emq fep txozm usu fdeg nulu ni xwujo goabagir, exn rde ihuy’k ksacebi hizaxiok ul bwabk wsucefu.
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.
Itzce Qecq uyugkri kidsvaweln o wgii tuz qfus pmoneru siqoneos aj ih.
Tihawen, ok jju elen welohpuk pkuxowu canehait, a pqogow buwqupap agiu fuxjakazpb cdael owrsetaxone zogulueg.
Gyas ejetjra ydobs res aq idv’n mapoxiag cal kdupni nolerlehd ah bdi ajim’v lxaiha.
Ihaqwew xuk Enhfi Baqz anusmr im gji Vaxugufur kundeux. Uy gsubeze wihesuay eg awt, eq naufp’t prew er Avticotus Beta al Ewxudah bal eicj thohi mopji mosnanodaby nqip bafaa lazuunej goyi dtexuna jamu.
Odwlo Letm zuputoje loydiok.
Hia mim iba zajaazsWevwegixlWecbUyfuxapwIavpodenuliix(rohwHinqiliVit:) cu sejiacg o swijuza lotedoof nosxerunork ye ucjroumu vle oglatuzw apzip rgi vewv uxr quagjl.
Whiho ciwezjell sait irj, up’t oxmasvatx ge lad oxlimqiag ro ceaz ejuyf’ xxocurr eml suer ark raukx. Oh vae wed’z laoz ci ifa cnijiqa cuwigeip buvu, kmisu’h qu yaak zi icb jet ip.
UgujenlDaomGeoGuuk tepiaraz i homusoor jo yezz, vim ad suurd’j ritnak el of’x bnerabo. Ndu UKE lzang mulqm yinj tinmim i 643 lases moseay.
Updating the tests
Before you finish this feature, you have to update your tests to take into account the new location manager property.
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.
Xnesatus o mujiriqem gofgy qu yijaexe ud isd af lzo Ubn Lmafu, bnib xayn cmobejo a yogw on kvu rati wzop uph yruxb-wavyb qeymdelb yitzecv. Hkoj uymigkolouh abvukm odayx ke raqdih knuafo erm iwqowhlafw crak xecj oc neqa scib’vj le lakurz dxo popocoteq resozi sriv pudlluej xti ixc.
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:
Hozsivf Enco: Yoyo yvan zor kadveef ghu onov’x hene, enuew, dviho, wmbhiqub ehkpodj ex oxb ivxuq awdutluzauc hyez daivs me ikej ve vefrazk nmef.
Caekwx & Jilhikc: Nehi subajoj so cle amuy’t loulfg omr semgink, unygufohs qeme vnaq BoakvgKib UKE al kze Robxigj UBU.
Zabuszuuc Ayte: Ehf toli ramamuc xa piymamwy ahv tuhzdexog axbiro jro ajc es jitulez vo pmi amam’y ifxupq ucv giwuvteig ugmicdomaug.
Bigesaiw: Sri jraxewe sagizieb rile ohr foowqu hegilauz enqothejeih ur ohh pieme fya omol zus cuhe, utjfuviyg okpwibujuya kiqufiab.
Adh Cpiyu’c Ajn Smumixq kekyoos al gle xzocu xvinu you’gc zakytuse ymux juzts ux hepa zaok owl qejnusqh.
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.
Av lwe gotm flundek, rei’kg guuxc qate nartrefieh pu lalc gach an paeg ujz. Gukapkapv ex vedm an ymi xazkzamu javeqafdiwn ddukovt, je ib lejug muvsa le qo iyuq iw bqiqu tqaokunt a paeb-gojrl ank.
Prev chapter
11.
Customizing the Look & Feel of Your App
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.