Martifan 5 Posted September 25, 2020 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
Dave Nottage 619 Posted September 25, 2020 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) 1 Share this post Link to post
Martifan 5 Posted September 25, 2020 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 🙂 1 Share this post Link to post