Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

NSApplication subclass that reacts to the GURL AppleEvent and opens a…

… URL.
  • Loading branch information...
commit 6217b6a5a7692ef528a035434d214a5cc4929168 1 parent c413be1
@uliwitness authored
Showing with 92 additions and 0 deletions.
  1. +48 −0 ULIURLHandlingApplication.h
  2. +44 −0 ULIURLHandlingApplication.m
View
48 ULIURLHandlingApplication.h
@@ -0,0 +1,48 @@
+//
+// ULIURLHandlingApplication.h
+// Stacksmith
+//
+// Created by Uli Kusterer on 2014-01-11.
+// Copyright (c) 2014 Uli Kusterer. All rights reserved.
+//
+// To use this class, change the principal class from NSApplication to
+// ULIURLHandlingApplication and add a CFBundleURLTypes entry like the
+// following to your Info.plist:
+//
+// <key>CFBundleURLTypes</key>
+// <array>
+// <dict>
+// <key>CFBundleURLSchemes</key>
+// <array>
+// <string>x-stack</string>
+// </array>
+// <key>CFBundleURLName</key>
+// <string>com.stacksmith.stack</string>
+// </dict>
+// </array>
+//
+// This claims an "x-stack:" URL scheme and hands the URL to application:openURL:
+// You can make up whatever bundle ID you want for the URL name.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@class ULIURLHandlingApplication;
+
+
+@protocol ULIURLHandlingApplicationDelegate <NSApplicationDelegate>
+
+@optional
+-(BOOL) application: (ULIURLHandlingApplication*)inApp openURL: (NSURL*)inURLToOpen;
+
+@end
+
+@interface ULIURLHandlingApplication : NSApplication
+
+-(void) setDelegate: (id<ULIURLHandlingApplicationDelegate>)inDelegate;
+-(id<ULIURLHandlingApplicationDelegate>) delegate;
+
+@end
+
+
View
44 ULIURLHandlingApplication.m
@@ -0,0 +1,44 @@
+//
+// ULIURLHandlingApplication.m
+// Stacksmith
+//
+// Created by Uli Kusterer on 2014-01-11.
+// Copyright (c) 2014 Uli Kusterer. All rights reserved.
+//
+
+#import "ULIURLHandlingApplication.h"
+
+@implementation ULIURLHandlingApplication
+
+-(void) didReceiveGetURLEvent: (NSAppleEventDescriptor*)URLEvent replyEvent: (NSAppleEventDescriptor*)replyEvent
+{
+ if( [self.delegate respondsToSelector: @selector(application:openURL:)])
+ {
+ NSString * theURLString = [[URLEvent paramDescriptorForKeyword: keyDirectObject] stringValue];
+ NSURL * theURL = theURLString ? [NSURL URLWithString: theURLString] : nil;
+ if( theURL )
+ [self.delegate application: self openURL: theURL];
+ }
+}
+
+-(void) finishLaunching
+{
+ [NSAppleEventManager.sharedAppleEventManager setEventHandler: self andSelector: @selector(didReceiveGetURLEvent:replyEvent:) forEventClass: kInternetEventClass andEventID: kAEGetURL];
+
+ [super finishLaunching];
+}
+
+
+-(void) setDelegate: (id<ULIURLHandlingApplicationDelegate>)inDelegate
+{
+ [super setDelegate: inDelegate];
+}
+
+
+-(id<ULIURLHandlingApplicationDelegate>) delegate
+{
+ return (id<ULIURLHandlingApplicationDelegate>)[super delegate];
+}
+
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.