Reputation: 61
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...?
Upvotes: 5
Views: 5530
Reputation: 137
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")
}
}
}
Upvotes: 1
Reputation: 405
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.
Upvotes: 4
Reputation: 145
You should write it like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"] options:@{} completionHandler:nil];
Upvotes: 7