Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a url on launch

What method must I implement in my cocoa application’s delegate so that on launch, it’ll open a url? (http/https, in this case) I’ve already implemented the url schemes, I just need to know how I can get my application to open on a url notification.

Update: I’m sorry, I wasn’t very clear. My application IS a browser that support https/http urls, but can only open them when it’s already running. What can I do to implement support for open urls in my app on launch?

like image 339
LinenIsGreat Avatar asked Jun 05 '26 05:06

LinenIsGreat


2 Answers

When an application finishes launching on OS X, NSApp (the global NSApplication instance for the program) sends its delegate the applicationDidFinishLaunching: message (via the notification system). You can implement that method in your delegate to handle the notification and open a browser window in response, using NSWorkspace. Something like the following would work:

// Your NSApp delegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.example.com/"]];
}
like image 163
mipadi Avatar answered Jun 08 '26 00:06

mipadi


It's not a delegate method. You need to implement an Apple Event handler for the getURL event.

As luck would have it, this is exactly the case Apple uses to demonstrate implementing an Apple Event handler.

like image 29
Peter Hosey Avatar answered Jun 07 '26 23:06

Peter Hosey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!