What’s New With Privacy?
Learn about the new privacy features introduced in iOS 14.5, including accessing the new privacy-focused image picker, handling location permissions and more. By Renan Benatti Dias.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
What’s New With Privacy?
30 mins
- Getting Started
- Understanding Library Permissions and the New Restricted API
- Working with Limited Libraries
- Designing for Limited Libraries
- Adding the New PHPickerViewController
- Working with Location Services
- Designing for Location Privacy
- Adding Location Data
- Conforming to CLLocationManagerDelegate
- Showing User Location on Map
- Adding When in Use Description to Info.plist
- Handling Denied Authorization
- Handling accuracy
- Understanding iOS 14’s New Clipboard Prompt
- Understanding the New Camera and Microphone Indicators
- iOS 14.5’s New App Tracking Transparency
- Requesting Permission to Track the User Activity
- Retrieving the Advertising Identifier
- Where to Go From Here?
Adding When in Use Description to Info.plist
Open Info.plist and add the following key:
- Privacy – Location When In Use Usage Description with a value of YourPrivacy uses your current location to add this data to your pictures.
This key allows iOS to ask for access to the user’s location whenever the user is using the app. If the app requires access to location data at all times, even in the background, you have to use Privacy – Location Always and When In Use Usage Description. iOS uses the value of this key as the reason on the alert when asking users for their location authorization.
Build and run the app again and try to allow location data once again.
Success! iOS displays an alert asking permission for the user’s location. The user can choose either Allow Once, Allow While Using App or Don’t Allow.
“Allowing Once” will prompt the alert again the next time the user opens the app, whereas “Allow While Using App” allows the app to access the location data whenever the user is using the app.
Allow location data and the section toggle for location becomes enabled. Toggle the section to see the map with the user’s location.
Handling Denied Authorization
So far so good. Users can select an image, add a caption and add their location data. But what happens if the user doesn’t allow location access?
The view simply doesn’t have any feedback that the user previously denied access to location data. This can cause some confusion should the user later want to add location information. To fix this, you’ll add text explaining the user denied location data and a button for opening the Settings app to change the permission.
In NewPictureStore.swift, after showAllowLocationButton
, add a new computed property:
var showOpenSettingsButton: Bool {
locationAuthorizationStatus == .denied ||
locationAuthorizationStatus == .restricted
}
This property returns true if the user denies access to location data. You’ll use it for showing the text and button for opening the Settings app.
Now, in NewPictureView.swift, find // TODO: Add open location settings button here
and add the following code:
if store.showOpenSettingsButton {
VStack(spacing: 16) {
Text(locationDeniedText)
.multilineTextAlignment(.center)
Button("Open Location Settings", action: openLocationSettings)
.font(.body.bold())
}
}
This code adds a text explaining why they can’t add location and a button for opening the Settings app.
Build and run. Deny access to location data to see the new text and button.
Neat! Now users know why they don’t have access to the location section when they deny location data and also how to allow this if they want.
Handling accuracy
Now that users can allow access to their location, it’s time to handle accuracy. Like before, there’s no indication whether the user allows full accuracy or reduced accuracy. On Apple Maps, a button indicating full accuracy is off and asking for full accuracy helps users understand their data is not precise. You’ll add this button now.
Open Info.plist and add the following key as a dictionary:
- Privacy – Location Temporary Usage Description Dictionary
Now, add the following key to the dictionary:
- temporaryAccuracyLocation with the value of YourPrivacy uses location accuracy to better pinpoint the picture’s location.
This text describes the app’s reason for requesting full accuracy.
Back in NewPictureStore.swift, inside the Location Authorization extension, add the following code:
func requestTemporaryFullAccuracy() {
locationManager.requestTemporaryFullAccuracyAuthorization(
withPurposeKey: "temporaryAccuracyLocation"
)
}
You call requestTemporaryFullAccuracyAuthorization(withPurposeKey:)
, passing the key you added in Info.plist, to show an alert asking for access to full accuracy with the reason you provided.
Finally, in NewPictureView.swift, add the following after // TODO: Precise location off button
:
if store.locationAccuracyAuthorization == .reducedAccuracy {
Button("Precise Location: Off", action: store.requestTemporaryFullAccuracy)
}
Build and run. Allow access to location data but leave precise location off to see the new button.
Understanding iOS 14’s New Clipboard Prompt
To make iOS more transparent, Apple has focused on privacy-focused features already built into iOS. These features make apps a bit more transparent whenever they access data that the user might think is sensitive. The new Camera and Microphone indicators and Clipboard prompt help keep apps transparent when accessing this kind of data.
The clipboard has been available since iOS 3, and many users have been accustomed to it ever since its introduction on computers. However, nothing stood between an app accessing and tracking what the user has been copying and pasting. Apps have full access to read and write to the clipboard.
Starting with iOS 14, the system shows a new prompt whenever an app copies the content of the clipboard, even if it wasn’t an action from the user.
That way, whenever an app reads from the clipboard, the user is aware of this and even knows where the content came from.
Understanding the New Camera and Microphone Indicators
The new indicators are also features to keep apps more transparent. Like the green light near the camera on MacBooks, iOS now displays a green circular dot at the top-right corner of the screen whenever an app uses the front-facing or rear camera.
And even after the app has stopped using the camera, you can still open the control center to see the name of the app that recently used the camera.
The same is true for the microphone. Whenever an app uses the microphone, an orange dot will appear at the top-right corner of the screen.
These indicators keep users aware when an app accesses the camera and microphone, increasing transparency and awareness to the user and also preventing some embarrassing moments when leaving the camera on during a work call. :]