Leave a rating/review
Notes: 14. Request Permission
The student materials have been reviewed and are updated as of January, 2022.
People use their phones for everything. From shopping, finding directions, looking up information - internet enabled phones are considered essential and they will go whereever the user goes.
This means, using Core Location, you can track users on a minute level which is a massive of invasion of privacy. This means, to track a user’s location, you need to request permission. And here’s the catch, you can only ask for permission once. More on this in a bit. There is two permission modes: Always authorization and When In Use.
First there’s Always Authorization. This means, the app will track you wherever you go. This means, the app is in the background requesting location data.
Next, WhenInUse authorization means the app receives location updates only when the user is actively using the app. In prior versions of Core Location, certain services were granted based on the permission level. For instance, region monitoring and background updates were only allowed with Always Authorization. As of iOS 14, When In Use acquires all the features of Always Authorization. This means, you think about your permissions based on how you want your app used versus what features it needs access to.
When your app is granted When In Use permission, a blue bar appears outside the app, letting the user know that their location is being tracked. Tapping the blue bar will open the app to the foreground. Always authorization does not provide this blue bar.
When you request an update, you must signify what kind of permission you are seeking. The user will be prompted for permission and in that prompt, you must disclose why you are asking permission. If the user selects Don’t Allow. That’s it. Your app can’t request location updates nor will the app be allowed to prompt again. This means it’s critical when you ask for location updates. You should only ask permission when the user needs those permissions versus asking permission on app startup.
If the user taps Don’t Allow, but later changes their mind, they can kind your app permissions by in Settings under Privacy and then Location Services. At which point, your app will gain location access. Since you can’t prompt the user for permission, you’ll need to inform them how to change their permissions.
To request always authorization, you call a method to request always authorization. iOS will prompt the user. You’ll see a prompt but doesn’t mention always authorization. In fact, it looks like it’s requesting When In Use authorization. If the user accepts When In Use, your app will be granted provisional Always authorization permissions. This is meant as a grace period. Later, the user will then be prompted one other time if they wish to keep always authorization enabled. At which point, your app will have full always authorization permissions. Another work flow is to request When In Use permissions. Once you receive it, later you can request Always Authorization. This will skip the provisional state since the user previously gave you permission.
Your apps can also receive temporary when in use authorization. These are temporary permissions that will go away once your app is no longer being used. You’ve seen some of the authorization modes, but iOS now supports accuracy as well. There are times when a user might like location data, but they may be uncomfortable providing exact location information. For this, iOS provides two types of location data. There’s full accuracy and reduced accuracy.
Full accuracy provides exact location data. This gives minute user location data which is useful for navigation and tracking such as hiking or running apps.
Reduced accuracy provides general location data. It works by a region where the user is located. The size of the region is determined by the location density so it may change. On average, the region is 5 kilometers where the user “may” be. This location is updated only four times an hour so while you may be able to track the general location of a user, you won’t be able to determine their exact location.
If you require full access such as providing directions can request temporary full accurracy. At which point, the user will be prompted for full accuracy. To request temporary full accuracy, you need provide a purpose key. This is a key in your info.plist that explains the reason for the request. This temporary ugrade works for as long as the user is using the app.
Once you have permission, there are lots of things you do with location but one of the most simplest and important things you can do is show the user’s location on the map. Once the user has granted you permission, just set the shows user location property to true on your mapview, you’ll finally see that blue dot.