我有以下代码
@interface MCMCustomURLSchemeHandler : NSObject
- (void)getUrl:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
@end
@implementation MCMCustomURLSchemeHandler
- (void)getUrl:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
// Get the URL
NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
stringValue];
NSLog(@" CUSTOM URL %@", urlStr);
//TODO: Your custom URL handling code here
}
@end
@interface MyObject : NSObject
+(void)aMethod:(id)param;
@end
@implementation MyObject
+(void)aMethod:(id)param{
@autoreleasepool {
[NSApp activateIgnoringOtherApps:YES];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptToLaunch];
[script executeAndReturnError:nil];
NSLog(@"hitting this point");
}
}
@end
int main(int argc, char *argv[]) {
@autoreleasepool {
MCMCustomURLSchemeHandler *mcmCustomURLHandler = [[MCMCustomURLSchemeHandler alloc] init];
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em
setEventHandler:mcmCustomURLHandler
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
[NSThread detachNewThreadSelector:@selector(aMethod:) toTarget:[MyObject class] withObject:nil];
//sleep(10000);
return 0;
}
}
在MyObject方法中,我正在启动一个Jar。直到我退出我的Jar,我没有得到回调。
当我的线程正在收听Jar时,如何确保我的应用程序继续处于运行状态。
我需要应用程序处于功能位置(睡眠不会帮助),因为它必须侦听其他一些事件(自定义URL)。