Open Link in Safari Swift 5.

This example to open particular link form your app to safari. That's redirect to app to safari browser. 


Swift 5
guard let url = URL(string: "https://iosdevcenters.blogspot.com/") else {
     return
 }
if UIApplication.shared.canOpenURL(url) {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
 }
Swift 2.0
let url : NSURL = NSURL(string: "https://iosdevcenters.blogspot.com/")!
if UIApplication.sharedApplication().canOpenURL(url) {
     UIApplication.sharedApplication().openURL(url)
}
Objective C
NSURL *url = [NSURL URLWithString:@"https://iosdevcenters.blogspot.com/"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}
Output:



Thanks.

Open Link in Safari Swift 5. Open Link in Safari Swift 5. Reviewed by KIRIT MODI on 21:52:00 Rating: 5

No comments:

Powered by Blogger.