[英]What's the Objective-C + Cocoa equivalent of Java + Swing's Event Dispatch Thread?
[英]Objective-C application's kAEGetURL event handler is not called after starting second thread
我有一個Cocoa應用程序(通過JNI)在單獨的線程中運行Java虛擬機。 該應用程序注冊事件處理程序以處理URL協議myprotocol://
。 注冊是這樣實現的:
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
handleGetURLEvent
是我的處理程序方法。
如果我不啟動JVM線程,則調用處理程序。 如果我啟動JVM線程,並且在JVM中運行的Java應用程序到達初始化AWT GUI的地步,則不會調用該處理程序。 有任何想法嗎?
我已經解決了 Java在加載Swing / AWT之后將自身安裝為AppleEvents的目標。 不知道為什么。 它只是替換了我的事件處理程序。 在Java設置事件處理程序之后,我再次設置了事件處理程序(替換Java的事件處理程序)。 我使用以下代碼設置事件處理程序:
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.