Skip to content

Instantly share code, notes, and snippets.

@beccadax
Created July 17, 2013 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beccadax/6017728 to your computer and use it in GitHub Desktop.
Save beccadax/6017728 to your computer and use it in GitHub Desktop.
NSApplication subclass adding a delegate method for opening a URL with your app.
//
// GSTApplication.h
// Gistapo
//
// Created by Brent Royal-Gordon on 7/12/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@protocol GSTApplicationDelegate;
@interface GSTApplication : NSApplication
@property (strong) id <GSTApplicationDelegate> delegate;
@end
@protocol GSTApplicationDelegate <NSApplicationDelegate>
@optional
- (void)gst_application:(GSTApplication *)app openURL:(NSURL*)URL;
@end
//
// GSTApplication.m
// Gistapo
//
// Created by Brent Royal-Gordon on 7/12/13.
// Copyright (c) 2013 Architechies. All rights reserved.
//
#import "GSTApplication.h"
@implementation GSTApplication
@dynamic delegate;
- (void)didReceiveGetURLEvent:(NSAppleEventDescriptor*)URLEvent replyEvent:(NSAppleEventDescriptor*)replyEvent {
NSString * URLString = [[URLEvent paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL * URL = [NSURL URLWithString:URLString];
if([self.delegate respondsToSelector:@selector(gst_application:openURL:)]) {
[self.delegate gst_application:self openURL:URL];
}
}
- (void)finishLaunching {
[NSAppleEventManager.sharedAppleEventManager setEventHandler:self andSelector:@selector(didReceiveGetURLEvent:replyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
[super finishLaunching];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment