ratkevich
ratkevich

Reputation: 117

UIApplicationOpenSettingsURLString not work in iOS 10

In iOS 10, do not open settings url:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

What is the problem?

Upvotes: 3

Views: 14187

Answers (4)

black_pearl
black_pearl

Reputation: 2699

Apple Swift version 5.3:

  if let url = URL(string: UIApplication.openSettingsURLString),  UIApplication.shared.canOpenURL(url){
         UIApplication.shared.open(url, options: [:], completionHandler: nil)
  }

Upvotes: 1

Ph.Homann
Ph.Homann

Reputation: 101

Swift 4

if let url = URL(string: UIApplicationOpenSettingsURLString) {
   if UIApplication.shared.canOpenURL(url) {
      _ =  UIApplication.shared.open(url, options: [:], completionHandler: nil)
   }
}

Upvotes: 8

Abhishek Mishra
Abhishek Mishra

Reputation: 1655

For iOS 11 +

UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[application openURL:URL options:@{} completionHandler:^(BOOL success) {
    if (success) {
        NSLog(@"Opened url");
    }
}];

Upvotes: 0

Almog_0
Almog_0

Reputation: 422

I did like that and it's works. I'm test it today!

 NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
 [[UIApplication sharedApplication] openURL:url];

Swift 3:

let urlObj = NSURL.init(string:UIApplicationOpenSettingsURLString)
if #available(iOS 10.0, *) {
    UIApplication.shared.open(urlObj as! URL, options: [ : ], completionHandler: { Success in

     })
} else {
      let success = UIApplication.shared.openURL(url as URL)
      print("Open \(url): \(success)")                            
}

Upvotes: 15

Related Questions