NSApplicationDelegate is active due to URL protocol

Hey! I have a Mac application configured to run under the myApp: // protocol, it is called in a browser, for example Safari, but I seem to be unable to perform an action when the application is called by this protocol. The delegate method should be something like this:

- (void)applicationDidBecomeActiveByURL:(NSURL *)protocol;

I don't know this because I'm new to Mac development, but I'm a little good at developing iPhone, so I know a way to develop an iPhone, but not a way to develop a Mac

+3
source share
1 answer

NSAppleEventManager. , AppKit , OS X - , URL .. UIKit . Apple.

: applicationWillFinishLaunching:

-(void)applicationWillFinishLaunching:(NSNotification *)aNotification {
    NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
    [appleEventManager setEventHandler:self 
                           andSelector:@selector(handleGetURLEvent:withReplyEvent:)
                         forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
    NSString *urlAsString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
    ... do something ... 
}

Info.plist.

+8

Source: https://habr.com/ru/post/1751701/


All Articles