View Full Version : Opening a URL
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];
Thanks!
(adding the minimum characters needed for a post)
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*
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.