How to open a URL in Safari programmatically

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

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

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

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

2 thoughts on “How to open a URL in Safari programmatically

  1. Hey i m trying to launch directly safari, without creating view controller. So i have written this code in didFinishLaunchingWithOptions: But it taking lot of time to open. Please help

    1. Pass I’m afraid – it’s not a real world scenario though because you wouldn’t open Safari as soon as your app launches (users might as well launch Safari right away). Perhaps add a button that will trigger opening the URL. It should happen instantly.

Leave a Reply

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