My question is identical to this question but it hasn't been updated in a while and Swift has changed a lot since it was asked so the answer might need to be refreshed. All I want to do is capture the url used to open my cocoa app, but the code never gets executed in my handler function. Errors are thrown in Console.app when I launch my application via the custom url scheme. Here are the errors:
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
OSErr AERemoveEventHandler(AEEventClass, AEEventID, AEEventHandlerUPP, Boolean)(spec,phac handler=0x7fff576b7f15 isSys=YES) err=0/noErr
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
-[MyApp.AppDelegate handleGetURLEvent:replyEvent:]: unrecognized selector sent to instance 0x60c0000039b0
OSErr AERemoveEventHandler(AEEventClass, AEEventID, AEEventHandlerUPP, Boolean)(GURL,GURL handler=0x7fff5661d680 isSys=YES) err=0/noErr
LSExceptions shared instance invalidated for timeout.
And my bare bones app:
Create a new Cocoa app named MyApp. In Info > URL Types, enter my app's bundle identifier in the Identifier field, and blue (for example) in the URL Schemes field. Add the following two functions to the AppDelegate class:
func applicationWillFinishLaunching(_ notification: Notification) {
let appleEventManager: NSAppleEventManager = NSAppleEventManager.shared()
appleEventManager.setEventHandler(self, andSelector: Selector(("handleGetURLEvent:replyEvent:")), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {
NSLog("heyo!")
}
Build and run my app. Quit it, then in Safari type blue://whatever in the address bar and hit return. The app opens, but the NSLog doesn't show up in Console.app and instead I get the errors I mentioned above. I would love to be stuck on how to parse the url, but I can't even get to that part yet. I'm running Xcode 8.3.3 (8E3004b) and Swift 3.1. Do you all get the same result as me? Am I calling the handler function wrong?