Similar to UIApplication, we can use NSApplication to open a URL on Mac. This will launch Safari automatically:
1 2 |
NSURL *yourURL = [NSURL URLWithString:@"yourwebsite.com"]; [[NSWorkspace sharedWorkspace]openURL:yourURL]; |
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).