내 응용 프로그램에 대한 사용자 지정 URL 스키마를 구현하려고합니다. 내 Info.plist에 필요한 라인을 추가했다. 지정된 URL (예 : myapp : //)을 호출하면 응용 프로그램이 시작됩니다. URL 체계 - Qt 및 mac
나는 URL을 처리 할 경우
, 나는 다음과 같이 발견했습니다@interface EventHandler : NSObject {
}
@end
@implementation EventHandler
- (id)init {
self = [super init];
if (self) {
NSLog(@"eventHandler::init");
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(applicationDidFinishLaunching:)
// name:NSApplicationWillFinishLaunchingNotification
name:NSApplicationDidFinishLaunchingNotification
object:nil];
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(@"%@", url);
}
@end
응용 프로그램이 실행되는 경우 위의 코드가 작동을하지만, URL이 호출되는 응용 프로그램이 종료 된 경우 이벤트가 포착되지 않았습니다. 나는 이것이 NSApplicationDidFinishLaunchingNotification이기 때문이라고 생각한다. NSApplicationWillFinishLaunchingNotification으로 변경하면 해당 이벤트가 감지되지 않습니다. 어쩌면 Qt가 나보다 먼저 처리하지만, 문제의 해결 방법을 찾을 수 없습니다.
그것은 그 청취 보인다 NSApplicationDidBecomeActiveNotification 알림은 문제를 해결합니다. 나는 그것이가는 것이 가장 좋은 방법이라고 생각하지 않는다. 그래서 나는 더 좋은 아이디어를 위해 열린 질문을 남겨두고있다. :) – birmacher