PDA

View Full Version : Opening a URL


Jake
2004.01.27, 10:42 AM
Is there anyway (simple) just to open a URL into a web browser with cocoa? I am sure a lot of uDevGames did that, but the code is still down.

GoodDoug
2004.01.27, 01:17 PM
LaunchServices will do this for you


#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSURL* aURL = [NSURL URLWithString:@"http://www.gooddoug.com"];

OSStatus err = LSOpenCFURLRef((CFURLRef)aURL, nil);

if (err != noErr)
{
NSLog(@"Oops! %d", err);
}

[pool release];
return 0;
}

OneSadCookie
2004.01.27, 02:34 PM
[[NSWorkspace sharedWorkspace] openURL:myURL];

Jake
2004.01.27, 04:43 PM
Thanks!

(adding the minimum characters needed for a post)

mars
2004.01.27, 06:34 PM
Anyone have a nice Carbon version for me?

thanks.

OneSadCookie
2004.01.27, 08:20 PM
GoodDoug's code will work in Carbon, just use an actual CFURLRef rather than a typecast NSURL*