How do I launch a URL using Cocoa (Objective C)

Status
Not open for further replies.

konan

Registered
I would like to have my application launch a URL. In windows, the code is like

ShellExecute(...,"http://www.mylink.com",...);

What is the equivalent command using Objective C and Cocoa?

Konan
 
Thanks dude,

Just in case anyone else wants to do this, the code is exactly as follows...

[[NSWorkspace sharedWorkspace] openFile:mad:"http://www.mylink.com"];

This one line will open the web site using the default web browser.

Konan
 
*actually*, you should use the openURL method.. even though it is more code :)

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:mad:"http://www.ithinksw.com/"]];
 
Why is the URL method superior to the document method? Will they not both open the default browser and go to the sight? Is there a performance penality? Please let me know what the difference is so I can make the decision.

The reason why I favor the document method, is that it is more generalized and I can use the same routine to launch a text file, image file or whatever.

If there is a solid reason for using the URL method, I'll make the switch.


Konan
 
well, the URL method I suggest because.. well, thats what Its made for :)

Kind of like how you are "supposed" to use a spoon when eating icecream, but you CAN use a fork.. its just kind of how you are supposed to use it :p
 
Well, if you have one of those nifty swiss army knives with a fork, spoon, knife (and maybe a rocket launcher), then that is more handy than a mere spoon ;)

Konan
 
Hey Joseph,

It turns out that the openFile method just "stopped working" for me. The only thing I can think of that is different is that my network has changed (perhaps openFile doesn't like my firewall???). In any case, I am using the openURL method instead.

Thanks for your help:D
Konan
 
Why is the URL method superior to the document method? Will they not both open the default browser and go to the sight? Is there a performance penality? Please let me know what the difference is so I can make the decision.
The reason why I favor the document method, is that it is more generalized and I can use the same routine to launch a text file, image file or whatever.
If there is a solid reason for using the URL method, I'll make the switch.
Konan

I tried both. The URL version worked, the other did not.
 
Status
Not open for further replies.
Back
Top