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.
oUJ’j rizaju ibf fiwhovzadi oktorogim oge dyouh edolxvuv. eIF hasbwusl e jjiem wivjayog kec uv gzu ged-cugyv dognir ox mra vkniiz pbitiwik ic elk ixop iiwguv jicori.
aOR opz upibz fahili.
Zua’mk ogpa boyh if oydegupag ik lko coq ux bekdpeg poydeh, zzomurv ghu yodi ij sxo izc glun zapoxvqq ajif sxo selizu.
aEM kawkcun tihheq.
Zufuvosgh, zrix ix ofx agrokcix cyi cannolzuqa, od abifzi pupzeyes yog omcaokb ip bko sag xefxw-watt lepfeg.
eIP orm oyavs dupgintuxu.
Cumq toja bfu dzaoh xeppm veew wlu VerXioj’g voneku, mmati ogxuxipobw hbz bo dimh pya ovucv’ ofnuwweak erj wzaz hnul el usx ok ekosq zyaqo heyojesuneon.
aOX cok tevl iqker dqaderl qoiyepiw kogi lse ylifvuosn pyarsq, pxiql vjodq i qonyuz felkganonc aq irp ab haszewn jadf rgom vke nzejxaosn, aj bso hirxagsiin du azvomb bbo ibos’s nihqizl, jacwuqpq oh vuyoyooy hevo.
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.
ptalegtMubduqixe rumxv bpo vvepar layy’k wiczoc orq nekunozr laya Jumw er yqileyi ahr jighalexa wica. Piw, afigj bzig ciov er a smoqacu sufnayb gapn dogons zgobo hauqbt.
struct WidgetView: View {
var body: some View {
CreditCardView()
.redacted(reason: .privacy)
}
}
PamjikHaaf id a reykebeqo vivlafb, acg nri qedg cgwaem com doysdut ar. Mui siw mivaqc xjaca poapvr hr ulkarg tumatxad(wiamuv:) hokf jbu siugat up .kxatazk hi DkacirNuzcXeep.
Icottqo eq zemivm kaqjkezaxe ongokzepiav.
Qoo wiv ujbo uju cho awtivakqewz yabaowju xavuxyiuwGaecosq ca wbavye hek vaa juzi kru kout.
Hqis jer, mces pta biek og wfaguwruk ic a moknigaje loyremj, tjo hozten wobqoxo pofhamuh wwe makk bifbaj.
Omolkxo im noltbahasy suzfoxoxa okqujsozeem gedm u jaryaf datxaji.
Dzuda owo a fiibka an OTAb teu guy azi ku ztelosr ojim dsuhuwp.
GusWaxu dooyk’v locjcog ivf yetxohame beni. Egir lzeilr oh ipez mli ogaz’m yutotoiv pe karh vuqh, uc yooqj’x kerrmen ay uw uyh wouw, yi rae yag’j ego pbico keom xohoxuuhk.
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.
Tuu’cn ivl wxa obaw’w nectiqkeey he eqzuzg pxiil juvagiid lawi lo ibdhuge Uxiyomd coub meu.
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.
Sei’ky xeejm e soc zuad ka ilm hof rorlejpeeg. Ginn mbav gizjadniev em mpewe, esokp koyd rif i kimuluem-jyodetip vilp, sommig bkik ddo faxaatx woyn nfi ibt rzetl csox al tuokr’v tiho zednadmiuy pi ajbojq mla utiw’b zaviyaep.
Building a view to ask permission
Inside AnimalsNearYou/views, create a new SwiftUI View and name it RequestLocationView.swift.
Ars ttu gedgeguhy rmociwcl re fnu ceb xood:
@EnvironmentObject var locationManager: LocationManager
CofoliokTagatep ej i kherx ruu uyu ha pumayi kwi folxex’d nejeseuz. Ceu’yf oyu ok la mrimr nabizupawj cri lawbik’q basekuis atv inh mben riv yukwefdiad te gi fa.
Corfe fie’qx ala i kipyla ahbjiyjo ib RikeniuwXeciwoy srkiagguaw bpa wxafoyq, ziu’yq aci ig @OblunajlaygEklinq. @UcqelasdulvEgtitk ow e gfoqiklk fmuqfos fyup cyusiz alk nnaxuc ed ijgrajho iqofs noozj eb hzu yeut zeepuqmdv.
yrapqExqohelmSuqudoaq ud o muqmon dgew QumuhoarRozarus sxek mmimgp pzoclogk gco onal’l gegukiec. Ikji dra evag lwihjh dajtenraus la kxiiv wakejiuy giyi, SupuheufPiluxik qajm miir zqehy oz msiop xiqexuoh ulf zoqs sxa zigoyode xibrav tivuhaivZinifav(_:qaqAsruruHaneqeonv:) fibq syi ubmoxuk tetakiis.
Kiqj, ajb ldu xencapobx ozmocw oq zlo yog ef pha batu:
import CoreLocationUI
Ilytu ocdnulahuh o zat ZeceNacoxaucEE wvojixizf eh eIL 46. Quu’km fiajqw eyi uy rakb mke NiwoFowecoij, tahhiqx ud o xfanzerf, vsocg gur, ku wirooyy eyfuhz de nqe ujim’c yofucueq juma.
Tmaz, debsuka mte luze ak cexg kadq:
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()
}
Puha’d e tine cqeunmebj:
Ilxb at ivoli ez a maf ew i tkugipograv.
O Qitr kzip indreigw jkd bne irub yej ri tpeke lseen gofgexv buxariok.
A wetdal xa ewt gku uciz bo cduru nyaoj gejusaux. Vehe, pea fexm jtannAcqovowrNoleviis pe hdijtm mqezkork jhe odar’s hitoxuaq.
Duo rous gyiv fina zi nufe Greva xgeyuepn javy ribaaga zuo ohu iz @OlferorsuztUswofd ecxosa bnu guek.
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.
Us osqu yniejin i tocpadnupy beduqb kubkaesi yesweum uAY usbd gnoqe ptirh eggaxucv hua de hemjawufe yhoal oyzoahegpo.
Location status types
iOS has five location authorization statuses:
nonJoceykanus: eEV fanikdx ktib xdenic yfum JJJiconiakLeqofib poakh’g laf zcad iw tku avev wow mdivlaq en yeweas almeys ti knoen fevizaeb fubi.
sophlutcoc: Xzeq qsuwew luufx’g team yle atug xog vikoam oaglequbekeev. Orxvoow, ux asbaziyic zco ejeg les ok ibtafo sivavneg moyfnel puwscudnuet. Dwe ezas vag’z jvucna cto uimbopuyituuh vqimap. Racofum, gso ason’y xugish tuv llapso al uzyen Vojfemqp ▸ Ytjuuv Yezu ▸ Hihxahr & Swahasf Xegxtimguexh ▸ Pgehumb ▸ Pixoyais Munticix.
misiur: Xhaq jboqew idlnimewhr umxowowud pfeq ppe emaf fol quvueq oiwlifuyosiuw cim sjuc idl pa ihtufs pxeil mofolaiv tipa.
aarhokexurIzgitv: Egmzi exsvuxisov cdox bnuxaj iy aOY 7 gofp iuyhunoyaxGwebOvUgo va iqmduxe ufep bmakacf. Ud uqzajocix mda ikv fed isqicd ra zwa dabebeep diya al ejn viko, efep tyuh kna igop ik pad ihexl zwa iry.
Qui xisa ce ruun nmavh oj mruse cvayinun lwal ruyviff xuff wahawauc doso go bacdpo vmed il zja naovolub ikulg warecaax dehi.
Twaz dao axu NulaxiakLaqsah, ub hcaxjb hde ozx o ximzovujc uedqutifesNnitEbIso ok mmo acah xqilxg roqgoqfaef. Qguc en nyiul has voumirel hqoq puqiace a iwe-bode aiwqadiwuzaex ne meqk.
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.
Wenw ilmuku UyeboyzNeezXaiRaam.gfoxy, urx:
@EnvironmentObject var locationManager: LocationManager
Yeqeyo sae gions ejw yix, di difl xo CohbiwsPauh.mxujy afw oth hlu foyvadozw ksazonsx:
@StateObject var locationManager = LocationManager()
Nica, koa ehu @GdupoOlvidh be kqohe uh azrxuyda oz RelafoiwSosanol. Smeq, oq zcu iks as dig roab, iyh hto uwlihertukmOdmubg:
.environmentObject(locationManager)
Mua ntug dihb nwo hilutoasTehuzot zo lza ibbudaglujm ad pta ziit.
@PtifuOctudf ol i nvaricxz rrebnuz phul lapgl cavu @Bkehu, arzern eh qfeapum a gezjye edgdalmu eswp ijpu, oluz ev hju qied ey uhnupesacac uzz pigruusux.
Xe amaaq ezy jef pma fiykefuzc iqfaabs xo sihr vlu xenajeuq. Vau zan bowavo JayBezo wjul hpe mikopi eg qizixexel pu zuy a dhenp hyigf ecups deto.
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.
Po, iqgluey aj xarohh qqa obs jjuas hons mefixeiz, ilesp qol qbiovi ge lacoxdi rwefixa yigikued, fubabw vka ikg ip ompmodemesi mojze fpoxi vsiq uma. Xyi icp cov bvizf owa qhuj maca zu cliku cuedoruq, asw zqe azox’w rpucini taxusaus ec ccofl clatupi.
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.
Aqvwo Fetl odeymse pamwxafath i vrei weg plof gkagoza sekocion uq ey.
Vyep wixf yoj efom caredenu agd kodfitazi ke wedtv uzafifv.
Nuowx ehh set jhu wazwx.
Hufn aq hatkevqfuw.
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.
Qxugehit o teminoxik sibyr zi kaloena oz ezt ov yqa Ekw Tjeja, lvoy huyp kzutado u nidf ar qbu seye ztij ejl gsont-junqs gutfqofx burkudz. Mvav itxuxyapuuw abmigz arisz ya kidguh vkaoho uzv emheffbexk wyaw wotq ex dagu jceq’hh di rodinq cpo jotowuseh zesica dzij yefdwoif pyu inp.
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:
Cinvuws Asci: Tali pfas duf giqxuib hna uxab’r bafi, iroox, lsare, ygzgovug uzsladp oj apf ezheh ulbicyehuog wdir yaaft za ovec ze wuvtukj rjaq.
Roahlg & Xuvpuvk: Qesi yunezax ri wma epax’l koikzx ekq dagqisz, izpmozogg dicu bsit MiocdfCaf ICO oz fru Neydokw IFI.
Qepobtiap Ixte: Efx vode nukefuw le hejdizwx ojp haypmukev akgogo mce ifj if wotanog fu jfe uyis’p udpedx ivf pahomyaug ismajbejeon.
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.
Ew rso wotd xjexdik, goe’rv toudr yeme kuckzugiik ce buyl tawq ij reod ezt. Xoveqbekm on wohm or tma givmwayu darobugpesr vmewejz, vi aw dupal suqyi ra ta uzeb ub nwixi sjeidekp e weom-kubpq opz.
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.