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...?
You should write it like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"] options:@{} completionHandler:nil];
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.
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")
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With