我想在 Mac OSX 上启动应用程序时收到通知。我发现Cocoa Application Finished Launch似乎回答了我的问题,但是appDidLaunch
当 Preview get 启动时回调方法没有被调用。
这是我到目前为止所拥有的,
#import <Foundation/Foundation.h>
#import <Appkit/Appkit.h>
@interface test_case: NSObject
-(void)run;
@end
@implementation test_case: NSObject
- (void)appDidLaunch:(NSNotification*)note
{
NSLog(@"app launched: %@", [note userInfo]);
}
-(void)run {
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(appDidLaunch:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
[[NSWorkspace sharedWorkspace] openFile:@"/Users/nah/Desktop/bsd_hacks.pdf"
withApplication:@"Preview"];
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
test_case * t = [[test_case alloc] init];
[t run];
}
return 0;
}
那么为什么appDidLaunch
不被调用呢?