How to open a URL in Safari programmatically

- by

Instead of loading a URL into a UIWebView we can also launch Safari to display it:

    UIApplication *mySafari = [UIApplication sharedApplication];
    NSURL *myURL = [[NSURL alloc]initWithString:@"http://www.mydomain.com";
    [mySafari openURL:myURL];

The method returns a BOOL value which will feed back if this operation was a success or not:

if (![mySafari openURL:myURL])
{
//  opening didn't work
}

openURL can open phone numbers (tel:), mailto: links, http: and https: links.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.