简体   繁体   中英

Objective-C application's kAEGetURL event handler is not called after starting second thread

I have a Cocoa app that runs Java Virtual Machine in separate thread (through JNI). The app registers event handler to handle URL protocol myprotocol:// . Registration is implemented like this:

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];

[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];

handleGetURLEvent is my handler method.

The handler gets called if I don't start the JVM thread. The handler doesn't get called if I start the JVM thread and the Java app running in JVM gets to the point where it initializes AWT GUI. any ideas?

I have solved it. Java installs itself as the target for AppleEvents after it loads Swing/AWT. Don't know why. It just replaced my event handler. I just set my event handler again (replace Java's one) after Java sets it. I use this code to set event handler:

NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];

[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM