Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open url in safari through cocoa app

I want to open a URL in Cocoa through my app in Safari only. I am using:

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: @"my url"]];

But the problem is that if my default browser is not Safari, then the URL gets open in some other browser. But I want my URL to open in Safari only. Please tell the solution.

Thanks :)

like image 612
Varun Avatar asked Feb 13 '14 04:02

Varun


People also ask

What is the URL of Safari?

Helpful answers. It's http://www.apple.com/startpage/ . then go into Safari > Preferences and click General > Set to current page.

How do I view a controller in Safari?

Opening Content in Safari View ControllerRun the app and tap the bottom button, "Open with safari view controller", to see the content now being displayed inside a SFSafariViewController instance. We've now let the user stay inside of our app and they have all the advantages of Safari.

How do I open a URL in Safari?

how to open url in safari from my app? When user click on the button open safari with given url.


1 Answers

let url = URL(string:"https://twitter.com/intent/tweet")!
NSWorkspace.shared.open([url], 
                        withAppBundleIdentifier:"com.apple.Safari", 
                        options: [],
                        additionalEventParamDescriptor: nil,
                        launchIdentifiers: nil)
like image 163
Sasha Prokhorenko Avatar answered Sep 28 '22 19:09

Sasha Prokhorenko