Jump to content
alejandro.sawers

iOS: Check granted accuracy authorization level

Recommended Posts

Posted (edited)

While this could frustrate some users, the truth is that approximate location access is not suited for most geolocation applications/features. Now if the user has given a incorrect location level access to the app (probably by mistake) it should inform the user so the permission level is corrected before accessing the features.

 

Now for Delphi FMX apps this is trivial in Android as there are two separate permissions for approximate and precise location access and a simple query helps to determine the access level granted. The culprit is iOS, as since iOS 14 the accuracy authorization level is separated from the location authorization status itself, and apparently there is no way to access such value from user code (accuracyAuthorization is a CLLocationManager instance property but such instance is buried on the implementation section of System.iOS.Sensors.pas).

 

So before patching this file and fighting the compiler about dependent units "compiled with another version of...", all without knowing if this would work at the end, I would like to know if somebody found another way to achieve this.

Edited by alejandro.sawers

Share this post


Link to post
3 hours ago, alejandro.sawers said:

I would like to know if somebody found another way to achieve this.

You can achieve this by writing code that uses CLLocationManager. Create an instance of it, and examine the value of accuracyAuthorization. If it is CLAccuracyAuthorizationReducedAccuracy and your app needs full accuracy, inform the user to:

  • Go to Settings > Privacy & Security > Location Services.

  • Select your app

  • Toggle the Precise Location switch on

Example code:

uses
  iOSapi.CoreLocation;

procedure TForm1.Button1Click(Sender: TObject);
var
  LManager: CLLocationManager;
begin
  LManager := TCLLocationManager.Create;
  if LManager.accuracyAuthorization = CLAccuracyAuthorizationReducedAccuracy then
    // Inform the user
end;

 

  • Thanks 1

Share this post


Link to post

Thanks Dave, this works like a charm and without patching anything. Hope Embarcadero adds an attribute/function to TLocationSensor (much like Authorized) to consolidate this.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×