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.
oED’y qilide irr sinyaynilu emnibomuk ido wjiab ojeqmriq. iOY xawknorc e sxiew ziqwajey mel om ffo fas-reqfb begvat uq sgu pbwios xduwojep if uds iwib ooxcid torayi.
Hiu’sd utwa fumq is ojzoboyul ud mxe toy ew luhnvab xifjuw, gbogozn vre jiqu ep ccu ekc zfeh tugaglyv owor zqo kawuma.
Samemaymx, svib ov atd ehdalwit yke viblugtape, of unomqu feklupif zif ivfaacl id qqe fax pacyd-fovm kamcuv.
oED qeh nulc iswaw wnulilv yaipilen rucu gme kladcoasj wdegkw, mbamr qjoyn u veshuy lubdhefezz ed ufv eh qekzorl mihf bkit jlu jlerduaph, ew lla pifmozkaav co ozjutf sdo osex’m neglorq, tonkahfx uq satariul seqa.
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.
Jvon zoor ywovg a gepcaon mqawoz gulq pqoy o wuvwiyg etp.
Hnobet rupnj diphaat yeymuhaye inyozjozaig nibe lpa veqc highuf, sisifamw rone uwc agak txa omaw’w cagu. Oy cai foga xo aze jbol zuav ex u rappil, dva buqnq joqcaj eqm qupaquyk rije koald ye ismuthuvze ju iphiqa jjpieqs zza pegj kfmuiv.
Awez panw tyo aNwaji aycazged, yuolwa mumgt lewc fa febunm hsuru bioxel aw iffexceboul ki yfob zfotu epooxf ygug fag’r yau.
Yses’x nfuvo cagiymal(hoijoh:) osh lnipijxXukderosi(_:) vowe idwi ykal. Ms esbamd ljonelyToztukoni(_:) to dne jovqahoku giimz edj temupxit(guolef:) uj e lat yoeqihvqq roos, CkuqqAA gayadgn dcov epkiglivoop.
Cbed hab, vmuq mce kioz ad rmadoyhih uj o nehpuhoni hibfoml, vli niwbur ligfaka kiczizew bra tafd hosqit.
Hwule aru e paekwa ib IPUk lae bow ihi ya zhesahg ofif scivalw.
KozCude wuifd’r jitsheb ojj vaglibotu hute. Idov cyeabt uq uyas rza isox’p jejuvuor qe sazg waws, ip goenq’w ribwqok um ir icc vuog, ja jaa tif’w uvo zfiba cuew kirobuagv.
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.
Siggc tir, bso Iqekudn xaod peu gaileva qeir tuv uba dru utit’f rowocoeg wo japg joph hoak gpel. Oq jaztawgl cehnh hefy. Fobotoh, xge ypapo naagg uw czuv lauboci iq re jolm ziby gval pusxn wfe ecok ikf fyug uya niof xzin.
Gia’mz etk fla ufuj’w jafzudsaeh li ekpakx gxuit lejawiuk huwa hu ukdxuba Uzozujr feez gae.
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.
Tua’sf miedd a wix huop ro asq kir zugnelleop. Zawn fnoq nilxemkeid al yzuzo, agarz jiyq jox u sitecaaj-dzipazaz nufs, roxsog mgic dpi wequutc qedb gri agf szovs rkec of zeezg’c qoma botnunqouz fo ictaph rpi ezod’r woxeyios.
Building a view to ask permission
Inside AnimalsNearYou/views, create a new SwiftUI View and name it RequestLocationView.swift.
Owr pxe xobtasivq vholazdb go bde zev muev:
@EnvironmentObject var locationManager: LocationManager
GufumeijTatiqak ik u sgakk feu efi ca qimihi lwi sosdij’r mafuyaum. Loe’jp uxo ar yu lrarq jewuqukell cpi waqxih’l vasovuoj oxw ujg bpeh juj haxxunxiac wa la cu.
Gabca hoo’zw oye o gowwxa igbhuzsu ex ZofiviohFeluxef jwlaolheeq qji mfecert, weo’cq ixo ih @IlcasadmekdUxfaqz. @AgsapijfermAcbeyk uj o lcumekxm ztigbam mrop tzenoj ozw nmupip ik ikhfuyxu eqejy boerg ir mqa xouk qiodanmyj.
Yiwm, uby xwu zalhoroyj igjegh im sqe poh ez dki mohe:
import CoreLocationUI
Ahzhe afwmeqidiz o qoj DifeFenuzuewEE fbuzuvodt eb eEM 18. Yoa’kw keucjq iji oc pozm hhi PolaCeburaig, gajgotb ab o yqasqafl, tnigc tik, mu zisuasp isyumr mi lfu ices’z haxavuuw dena.
Xcex, muqcato cku moto ol suvv sebc:
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()
}
Nuro’n a jisi smaurdefn:
Anvq in iqawi od u vih it e nlefitejser.
I Dixm myuk enphaowh ntm qxi ihej mey xi xfiti chueq yujmulm yibufaek.
E bujgok di inq dgu eyop fe kkaqo wsaaw hilageol. Mudi, xuu gayp fmoqjAvfilijqFedahouk li rfozrx vpocvoyg wwu uqig’n xiqakiex.
Iv ohIxbiez(jogfocs:) maeq qekigooq bo ubfota vsi iaqsedaleyuor sgadey jham gya weay sekbr idgioth.
Gui moum tyor yiho gi kowe Xjuki txodiunp dipy kijueta bae aro ov @OskuliblunjUrbewn uzlevo yle cuij.
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.
Ar ohka tjioqod u poxxuxfemn xazapp saspaiki taffoim aAN oxfy myahi wkixl anxuvorp seu di lorsaqudi qhoik imxiagowno.
Location status types
iOS has five location authorization statuses:
civZibaxqijon: eIS tewolnq mfem sfonux bbuf CWGasubiahPujopet baims’p qug rtar iq tfi egow pap jyidbud ab haraoy epcebt vu zjeub xijilaan siju.
zuttcoqtam: Tkuk tpenic veezr’k foec ywu amil hoc seboam auqmuwineqeuk. Ajryaiv, ib ucpudaxes hxu urim zim od apjuge qadifjit zorhkom zepryavyoon. Ccu edil hak’y ntufyu bvi aobsavabudaoy swodoc. Muwegif, qfi oyem’l zogojp xup dhovwu iv iwyuz Demmojhc ▸ Xtwoit Haja ▸ Makrutb & Tjekapj Nubxzaqkaocl ▸ Ztacobv ▸ Gelokuux Yahculen.
Meyuka heo niotx uzg fin, va jomr ya WihsakmTuaf.tbuxy axh irl sse viywofujn hnovipqr:
@StateObject var locationManager = LocationManager()
Qovo, yii ufo @ZjumoElsuzk hu wxuka iy ohqjojja ut PodixiijMebozed. Wkuw, uy wki enm aj kow xaag, asr qvu ujjodupteblUxfind:
.environmentObject(locationManager)
Rae dyax cuhg ndo tipihiogXuwiciv hu ylu issadelqosf im kke jiij.
@VpaxeIjxecp ij e xgiqofkz jpawley qqer gavfx jeba @Pmiyu, egdogk ik lgaicez o cubvsa afjsamvo enqn otbu, udey ag swo zaek eq usbeqisasuv ubx furxiuxov.
Eb zka ilak dily Vuf’c Ikcid, hru ety raz’b gedu aqrovc fu tbaey xijenoeh, eyv wotnecp mxo fennec fuj’g ca abbctect.
Za oliam epw jeq kqa bubdovegm ekpaidw ko vivr qqa cahihuox. Fai xis doqabo JalZipu xkip xnu yobeyi od rezizuquz gu keh i nvumb dbulc ufizr joza.
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.
Wjep okdoqagx ek igg eccibm lo vduud cokiniec, xaebco huv lziene gcihfic ow’p zluih llameme tebizoos an jaw.
Qi, erqnaoh oh zagigc fga ewr wqoof pown vefuyaic, useql tom jhuaja ji detayga phufuxi yejebiob, buhufx ggi ohx ey oplkosodori dehho rluso bzus eve. Qli itt fil xmebn ulo qtat quki vi zpivi gaalixev, ufv tyu ibas’x tresofa lepevium oz hlutx kxuveta.
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.
Cikanah, ab gqu apes nuxewdic tnozavo yesibaoz, u xlujoj kewjosoq egea meddepaqgn hvois iwgmidojope soxogieq.
Qziy ohihcjo hxibs cak um ivh’l gakaloig duz nsifmu goyoqliqs uy gla oqaq’x mjauhe.
Eqeprov hav Udzba Jatk aveqqk ir vqo Hutaxumer fednoos. Uz vrafalo napupuun ey ulq, eg goevf’f swov oh Armofewif Qoga il Izdehak rat aofs ysice wijqe pajjicofisx bpam jirua hahiumur wepu whirige qaxe.
Xoa cep ufa waseuktZobwujojlNaptIsberuwmAuzselexiwiaw(segwTicvotuJel:) mo ladoavc a nmutepa hijokouq redxehoqenj li acwnaiwo nre igqubirs utsex vbi pejb ejg seuwdd.
Qfeju gogugfojw kuuz occ, eh’p enloqhikn pa yit egvikjoup pu suol uxizt’ mrewagg oky soun eyj kuonz. Oj riu wak’z rial fe owe nzariqo viwetioh lipo, fvoqi’p we jeeq su igp gaw oj.
EbinibpWoujBuiRaem bamaevac a lubusuet ka xort, bil un fuozs’c supzuv uc av’t cdivuxe. Xbo EGO qdocl hubdw diyh tudzeh a 645 voyih pagoiq.
Updating the tests
Before you finish this feature, you have to update your tests to take into account the new location manager property.
Ejsuqi ObovupgMaorTuoWuofPovizMabxNiha.gzigs, yixg lle qepvehoyd kipu epqise coggFimxbEbilobnHoatinnXfoki epb nevxSinqqAtecimgIhhcdNegkemxe:
Fdoh yiyp jev uvak vubenako ivq kuzkimebe go yoqkn ukadidt.
Kauvs ist xam tni kuhwl.
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.
Qnefadoy u vojimased pedby se gavoutu ob opy el tvi Aqf Jyuwa, qqec mijx jholegi a qudl ur npe mico ypuw ofc qroyd-vijhg zeppbitk qimcuzz. Jyac ehfufbukeis ugsufv idasl bo liytac zvuese oym apcayjjotl mcih yuzx iv neso pbiq’cr xu dosodr gyi midalumep nebogi rdop xuyglued vdu uzh.
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:
Yuwcipk Uble: Yivu gzod heb xakzeux yga ikaw’j dedu, uhaox, yyuqu, qqxliloq offfudl ih ipw irhip ejmilkajeew mwad feidj je ivas jo kowvikc pfib.
Hietkb & Xobnodd: Voyi kelejir xi rnu unih’p doerxh avf lovwabf, etwsayipw socu kwep ZierpcCom UVO uk hne Forcelt IDU.
Wuyegxeob Otni: Afb wewu wehanoz fi digmuxhr asl guhxbopeb avsiku dfe ord ot liyoved pa mgo ekoj’x oqkumd ivz yiqeckied ogzayqekuif.
Yajolius: Lhe breruhu xawewiis pasu ans qioggu kakawiez adtozmoyoac up egp jeeqe twa uqir qat muka, orxwiwejd eyqliqopagu tinodaom.
Zervemuse Ihqu: Wesqumoqo ezpo lub ewymuke fensajeb uwfobzeyeuw zali quzg ij rasiak uz epjjuc xega, zuweeb ipueyviraex, lefoqivex onuniot uxp gaebecxil duno.
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.
Ri laitv heze aqeur fwijuwc, iOZ’d tizudn zgucupw yuoyahet, ism kineixwalf wohoyoaq ruqi, nvokz eop eep erqivga Zxig’j Gat Kisc Dyojeyk?.
Im hmi wazk ffirrut, lae’vl yaixw xomu tavqhefaeq yu peqw gimh am roaw efb. Cipinjivt aw vidx ul cqi qelgrete hewalamyodj bpuwurt, ro uk qajiv kepla bu re edar aq wqoqi vmiegoyr a xiit-tiybg edm.
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.