IOS 8 Swift sending user directly to location services from Alert dialog box

When the user’s location services are turned off, I want to invite them to turn on using the UIAlertController. One of the parameters in Alert Controller must take them directly in the location services (for the OS, not for the application). Right now, I got to the point that I was able to send the user permissions for my specific application, but not for general OS location settings. Is there a way to send the user directly to OS location settings from UIAlertController?

Here is the current code (located in viewDidAppear):

if (CLLocationManager.locationServicesEnabled())
{
    daMap.delegate = self
    daMap.mapType = MKMapType.Satellite
    daMap.showsUserLocation = true
    // do some other things...
} else {
    let alertController = UIAlertController(
        title: "We Can't Get Your Location",
        message: "Turn on location services on your device.",
        preferredStyle: .Alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    alertController.addAction(cancelAction)

    let openAction = UIAlertAction(title: "Location 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)
}
0
1

"", "". - , , - ( , UIAlertController).

NSLocationWhenInUseUsageDescription plist ( ) .

, plist :

key: NSLocationWhenInUseUsage
String value: Turn on location services on your device.

, :

key: NSLocationAlwaysUsageDescription
String value: Turn on location services on your device.

iOS8 , , , , .

, . , , , ..), , , .

, , , ( ), , .

+2

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


All Articles