Iphone again asks permission to current location

Case: for the current location, the user chose "Dont allow" to install the application, so is there a way I can request again for the user's location and run my own iphone request for the current location?

I saw several posts on stackoverflow, but there are old ones, is there a solution for calling a new sdk or someone found a way,

Message: CLLocation requests permission again

+6
source share
5 answers

Unfortunately, you cannot do this. One thing you can do is invite the user to change the location settings.

if (![CLLocationManager locationServicesEnabled]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" message:@"To re-enable, please go to Settings and turn on Location Service for this app." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } 
+8
source

It seems that the accepted answer is not quite right. [CLLocationManager locationServicesEnabled] checks if location services are enabled as described in the documentation.

Gets a Boolean value indicating whether location services on the device are enabled. The user can enable or disable location services from the Settings application by switching the "Public Services" switch in the "General" section. Before sending location updates, you should check the return value of this method to determine if the location services user is allowed for the current device. Location services request users the first time they use location information in an application, but do not request subsequent attempts. If the user refuses to use location services, and you still try to run location updates, the location manager reports an error to his delegate.

If you want to check whether the user has been granted permission to use their location, you must check the [CLLocationManager authorizationStatus] . If the status of your application is kCLAuthorizationStatusDenied , it means that the user explicitly rejected your application when he asked for permission. You can use this and report it to the user.

+5
source

in ios8, the apple introduced the constant UIApplicationOpenSettingsURLString, which is the location of the device’s “settings” view.

you can encode the following (in fast) to direct the user to the settings view:

 switch CLLocationManager.authorizationStatus() { case .AuthorizedWhenInUse, .Restricted, .Denied: let alertController = UIAlertController( title: "Background Location Access Disabled", message: "In order to be notified, please open this app settings and set location access to 'Always'.", preferredStyle: .Alert) let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) alertController.addAction(cancelAction) let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in if let url = NSURL(string:UIApplicationOpenSettingsURLString) { UIApplication.sharedApplication().openURL(url) } } alertController.addAction(openAction) self.presentViewController(alertController, animated: true, completion: nil) } 
+5
source

I don’t think it’s possible to ask permission again. But if you really need the user's location, you can display a warning instructing them to enable it from the settings.

0
source

This is what I did based on previous answers: (this is in MonoTouch C #, but easily translatable to Swift or Obj-C)

The next one requests permission and then proceeds to update the location, if one is provided. Otherwise, the next time the user comes; if location services are disabled or rejected, a message will be displayed asking for permission / activation with a redirect to the settings

 //Location Manager (foreground) CLLocationManager locMgr = new CLLocationManager(); locMgr.PausesLocationUpdatesAutomatically = false; if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { locMgr.RequestWhenInUseAuthorization(); } if (CLLocationManager.LocationServicesEnabled && CLLocationManager.Status == CLAuthorizationStatus.AuthorizedWhenInUse) { //set the desired accuracy, in meters locMgr.DesiredAccuracy = 150; locMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { Console.WriteLine(e.Locations); }; locMgr.StartUpdatingLocation(); } else if (!CLLocationManager.LocationServicesEnabled || CLLocationManager.Status == CLAuthorizationStatus.Denied) { var alert = UIAlertController.Create(NSBundle.MainBundle.LocalizedString("Location access", "Location access"), NSBundle.MainBundle.LocalizedString("Please check location", "To show your position on the map, you have to enable location services and authorize the app"), UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, null)); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { alert.AddAction(UIAlertAction.Create(NSBundle.MainBundle.LocalizedString("Go to settings", "Go to settings"), UIAlertActionStyle.Default, delegate { var url = new NSUrl(UIApplication.OpenSettingsUrlString); UIApplication.SharedApplication.OpenUrl(url); })); } PresentViewController(alert, true, null); } 
0
source

Source: https://habr.com/ru/post/947808/


All Articles