Requesting "Always" Location Access in iOS13 for Geofences

Hi,


I have an app that uses geofences. For this, the "Always" location permission needs to be granted.


I've always used requestAlwaysAuthorization() for this at the time where the user signals their desire to set up a geofence (the apps functionality is they get a notification when they enter this geofence with some up to date data about it - there is a settings screen where they can choose to start receiving this notification, if they choose to do this, at this point I request Always permission so I can set the geofence)


I notice from 1:11:36 in the 2019 Platforms State of the Union - and from testing in the Xcode 11 Beta that calling request**Always**Authorization() now no longer gives the user the user the option to allow always. It only gives them the choice of While Using App, or allow once. The user apparently now has to grant the "While Using App" permission first, then according to the state of the union the app must ask for "Always" location later from the background. They didnt elaborate on how you will do this from the background or when you should.


I'm just wondering how this is going to work for geofences? I want to be able to set up the geofences within the app as this is the best experience for the user, rather than them having to leave the app to give background permission, then re-enter the app to set up which geofences they want. It also seems a poor experience for them to have to grant the permission twice - once for in use, then again for always, when I just want Always permission.


I do handle the app in a degraded state when the user chooses "While using app" - as this has been the requirement up until now. But there are areas of the app where it makes no sense for me to prompt and the user only be given the choose to accept the while using permission such as the use case noted at the start of this post, where I'm specifically asking the user if they want to set up a geofence.


Is there a better flow that can be done to request Always permission while still in the app - or perhaps a different permission status for geofences?


Thanks

I am facing same problem from iOS 13.
I am facing the same problem in iOS14.

When I ask for requestAlwaysAuthorization() the user only have the option of choosing between "While In Use" or "Only Once".
If the user chooses "While In Use" I get the status on the delegate of "authorizedAlways".
However, when I go and check on the Location Services in Settings permission granted is "While Using the App"

Anyone facing the same problem in iOS14?
Is there any solution for this?
please make sure to add the following to info.plist
Privacy - Location Always and When In Use Usage Description
Privacy - Location When In Use Usage Description
Privacy - Location Temporary Usage Description Dictionary -> wantAccurateLocation
checkout this post
medium.com/better-programming/handling-location-permissions-in-ios-14-2cdd411d3cca

Code Block
import UIKit
import CoreLocation
class ActivitiesMapVC: UIViewController {
private let locationManager = CLLocationManager()
var locationStatus = "..."
override func viewDidLoad() {
super.viewDidLoad()
self.locationConfig()
}
func locationConfig(){
self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.requestAlwaysAuthorization()
}
func checkLocationAccuracyAllowed() {
switch locationManager.accuracyAuthorization {
case .reducedAccuracy:
locationStatus = "approximate location"
case .fullAccuracy:
locationStatus = "accurate location"
default:
locationStatus = "unknown type"
}
locationManager.startUpdatingLocation()
}
func requestLocationAuth() {
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyReduced
let url = URLs()
switch locationManager.authorizationStatus {
case .denied: // Setting option: Never
let alert = UIAlertController(title: "Location Denied", message: "Please enable location", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: { [weak self] _ in
self?.dismiss(animated: true, completion: nil)
}))
alert.addAction(UIAlertAction(title: "Go to Settings", style: .default, handler: { _ in
url.openURL(urlString: URLs.locationAppURL)
}))
alert.firstActiveTemplateAlert()
self.present(alert, animated: true, completion: nil)
case .notDetermined: break
case .authorizedWhenInUse:
// While using the app
locationManager.requestAlwaysAuthorization()
locationManager.requestLocation()
case .authorizedAlways:
// Always allow
locationManager.requestAlwaysAuthorization()
checkLocationAccuracyAllowed()
case .restricted: // Restricted by parental control
self.dismiss(animated: true, completion: nil)
default:
break
}
}
}
extension ActivitiesMapVC : CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else { return }
print(location.coordinate.latitude,location.coordinate.longitude)
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
let status = manager.authorizationStatus
let accuracyStatus = manager.accuracyAuthorization
if(status == .authorizedWhenInUse || status == .authorizedAlways){
if accuracyStatus == CLAccuracyAuthorization.reducedAccuracy{
locationManager.requestTemporaryFullAccuracyAuthorization(withPurposeKey: "wantAccurateLocation", completion: { [self] error in
if locationManager.accuracyAuthorization == .fullAccuracy{
locationStatus = "Full Accuracy Location Access Granted Temporarily"
}else{
locationStatus = "Approx Location As User Denied Accurate Location Access"
}
locationManager.startUpdatingLocation()
})
}
}else{
requestLocationAuth()
}
}
}

Requesting "Always" Location Access in iOS13 for Geofences
 
 
Q