5

I'm working on iOS 10 app and since openURL is deprecated I need some help using the new method. Problem I'm facing is not knowing what to pass in the options parameter.

Here's my code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"] options:nil completionHandler:nil];

Compiler gives warning: "Null passed to a callee that requires a non-null argument."

Confused what I should pass in...?

jkdev
  • 11,360
  • 15
  • 54
  • 77
user6840013
  • 61
  • 1
  • 4
  • 1
    http://stackoverflow.com/questions/38964264/openurl-in-ios10/40188482#40188482 – Ed. Nov 08 '16 at 17:27
  • 1
    Possible duplicate of [OpenURL in iOS10](http://stackoverflow.com/questions/38964264/openurl-in-ios10) – KSigWyatt Feb 05 '17 at 19:51

3 Answers3

7

You should write it like this:

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"] options:@{} completionHandler:nil];
aNa12
  • 145
  • 1
  • 10
4

For Swift 3 you should use this:

 UIApplication.shared().open(url: URL, options: [String: AnyObject], completionHandler: ((Bool) -> Void)?)

for example I used in my project:

let url = URL(string: "http://kaznews.kz")
UIApplication.shared.open(url!, options: [:], completionHandler: nil)

this is simplest way without options and handler.

Yerbol
  • 405
  • 3
  • 6
1

For iOS 10.2 and swift 3.1

private var urlString:String = "https://google.com"

@IBAction func openInSafari(sender: AnyObject) {
    let url = NSURL(string: self.urlString)!
    UIApplication.shared.open(url as URL, options: [ : ]) { (success) in
        if success{
            print("Its working fine")
        }else{
            print("You ran into problem")
        }            
    }
}
JOM
  • 8,139
  • 6
  • 78
  • 111
Roshan Sah
  • 137
  • 10