Andrew Chang
Andrew Chang

Reputation: 1319

Cocoa: How to force open a website via Safari (NOT default browser)

I know I can use -openURL method in NSWorkspace class to open a URL. But because of some reason, I want to open a website via Safari instead of system default browser.

How can I achieve that?
BTW, this question is about OS X, not iOS.

thank you at advance!

Upvotes: 2

Views: 649

Answers (1)

jaydillyo
jaydillyo

Reputation: 316

NSURL* url = [NSURL URLWithString: @"http://apple.com"];
[[NSWorkspace sharedWorkspace] openURLs:@[url]
                withAppBundleIdentifier:@"com.apple.Safari"
                                options:NSWorkspaceLaunchDefault
         additionalEventParamDescriptor:nil
                      launchIdentifiers:nil];

Upvotes: 3

Related Questions