【发布时间】:2016-02-15 23:54:01
【问题描述】:
我希望在 Mac OSX 上启动应用程序时收到通知。我找到了Cocoa Application Finished Launch,这似乎回答了我的问题,但是当 Preview get 启动时,回调方法 appDidLaunch 没有被调用。
这是我目前所拥有的,
#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?
【问题讨论】:
标签: objective-c macos appkit nsworkspace