Jump to content
Sign in to follow this  
Martifan

iOS Location

Recommended Posts

If someone can, please help. 

How can I control on iOS permission if users haven’t turned on their location ? And if it is not enabled, display a message.

Thank you

P.S. If possible an example on Delphi

Share this post


Link to post

I've already answered your email, but for the benefit of others:

 

On iOS, you can check what the user has authorized with:
  TCLLocationManager.OCClass.authorizationStatus

which will return one of the following values:

  kCLAuthorizationStatusAuthorized = 3;  // User has authorized location services ("always" on iOS 8+)
  kCLAuthorizationStatusDenied = 2; // User denied authorization for your app, or they turned off location services in the device settings, or the device is in airplane mode
  kCLAuthorizationStatusNotDetermined = 0; // App is yet to request permission for location services
  kCLAuthorizationStatusRestricted = 1; // User is unable to authorize location services due to restrictions such as parental controls
  kCLAuthorizationStatusAuthorizedAlways  = kCLAuthorizationStatusAuthorized ; // See kCLAuthorizationStatusAuthorized
  kCLAuthorizationStatusAuthorizedWhenInUse = 4; // User has authorized location services only when the app is in use 
 
(from iOSapi.CoreLocation unit)
 
If your app needs location services and the status is kCLAuthorizationStatusDenied, you could present a message asking if they would like to change the settings, and if they do, execute OpenSettings:
uses
  Macapi.Helpers, iOSapi.Foundation, iOSapi.UIKit, iOSapi.Helpers;

function UIApplicationOpenSettingsURLString: NSString;
begin
  Result := CocoaNSStringConst(libUIKit, 'UIApplicationOpenSettingsURLString');
end;

procedure OpenSettings;
begin
  TiOSHelper.SharedApplication.openURL(TNSURL.Wrap(TNSURL.OCClass.URLWithString(UIApplicationOpenSettingsURLString)));
end;

This will take them to the Settings app, and show the settings specific to your app (there may be a little delay in it changing to the settings for the app)

  • Thanks 1

Share this post


Link to post
1 hour ago, Dave Nottage said:

I've already answered your email, but for the benefit of others:

 

On iOS, you can check what the user has authorized with:

  TCLLocationManager.OCClass.authorizationStatus

which will return one of the following values:


  kCLAuthorizationStatusAuthorized = 3;  // User has authorized location services ("always" on iOS 8+)
  kCLAuthorizationStatusDenied = 2; // User denied authorization for your app, or they turned off location services in the device settings, or the device is in airplane mode
  kCLAuthorizationStatusNotDetermined = 0; // App is yet to request permission for location services
  kCLAuthorizationStatusRestricted = 1; // User is unable to authorize location services due to restrictions such as parental controls
  kCLAuthorizationStatusAuthorizedAlways  = kCLAuthorizationStatusAuthorized ; // See kCLAuthorizationStatusAuthorized
  kCLAuthorizationStatusAuthorizedWhenInUse = 4; // User has authorized location services only when the app is in use 
 
(from iOSapi.CoreLocation unit)
 
If your app needs location services and the status is kCLAuthorizationStatusDenied, you could present a message asking if they would like to change the settings, and if they do, execute OpenSettings:

uses
  Macapi.Helpers, iOSapi.Foundation, iOSapi.UIKit, iOSapi.Helpers;

function UIApplicationOpenSettingsURLString: NSString;
begin
  Result := CocoaNSStringConst(libUIKit, 'UIApplicationOpenSettingsURLString');
end;

procedure OpenSettings;
begin
  TiOSHelper.SharedApplication.openURL(TNSURL.Wrap(TNSURL.OCClass.URLWithString(UIApplicationOpenSettingsURLString)));
end;

This will take them to the Settings app, and show the settings specific to your app (there may be a little delay in it changing to the settings for the app)

Thank you very much, as always everything works 🙂

  • Like 1

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
Sign in to follow this  

×