Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone ask for Current location permission again

Case: For current location, the user selected "Dont allow" on app install, so is there a way that I can ask again for the user location and trigger the native iphone alert for current location??

I seen some posts on stackoverflow but there are old, is there a solution now to call in new sdk or someone found a way,

Post referred: CLLocation ask again for permission

like image 908
Raheel Sadiq Avatar asked Jun 21 '13 06:06

Raheel Sadiq


People also ask

Why does my iPhone keep asking for my location?

iOS 13 will keep asking you about the apps using your location in the background unless you tap “Change to Only While Using.” iOS won't warn you about apps that can only access your location while you're using them. The good news is that we've noticed these prompts becoming less frequent over time.

How do I fix my current location on my iPhone?

If you can't find your current location on your iPhone, iPad, or iPod touch. Turn on Location Services and Location Access for Maps. In the Settings app, tap Privacy, then tap Location Services. Make sure Location Services is on, and make sure Maps is set to While Using the App or Widgets.


2 Answers

Unfortunately you can't do that. One thing you can do is to prompt 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];
}
like image 149
manujmv Avatar answered Nov 15 '22 17:11

manujmv


in ios8, apple has introduced a UIApplicationOpenSettingsURLString constant which is the location of the device's "settings" view.

you can code the following (in swift) 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's 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)
}
like image 29
kennydust Avatar answered Nov 15 '22 17:11

kennydust