0

I had do a test first,then post my answer:

The document said:openURL: is deprecated in iOS10.Use openURL:options:completionHandler: instead.

无夜之星辰
  • 5,426
  • 4
  • 25
  • 48
  • Possible duplicate of [How to jump to system setting's location service on iOS10?](http://stackoverflow.com/questions/39940219/how-to-jump-to-system-settings-location-service-on-ios10) – chedabob May 22 '17 at 08:19
  • @chedabob But no right answer for Objective-c there. – 无夜之星辰 May 22 '17 at 08:22

3 Answers3

0

Before iOS 10,you can use:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]];

After iOS 10,you'd better use:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"] 
options:[NSDictionary dictionary] 
completionHandler:nil];
无夜之星辰
  • 5,426
  • 4
  • 25
  • 48
0

Open Location Service Setting in Swift 3:

if let url = URL(string: "App-Prefs:root=Privacy&path=LOCATION") {
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.openURL(url)
    }
}
Lionking
  • 570
  • 6
  • 9
-1

In Swift 3.0

let url = URL(string: "http://google.com")!
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
        else{
            NSLog("Cant open url")
        }
Federico Picci
  • 1,105
  • 10
  • 17