How to open a URL in Safari (on Mac in Cocoa)

Similar to UIApplication, we can use NSApplication to open a URL on Mac. This will launch Safari automatically:

Apparently this method returns a BOOL to indicate success of the operation. Note that this is does not indicate success at all, because as long as Safari can be launched, this will return YES – no matter if the URL can be displayed or not.

Test for internet connectivity before use (for example with Tony Million’s Reachability).

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.

Leave a Reply

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