Created
July 17, 2013 04:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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