Post

Replies

Boosts

Views

Activity

Program not handling NSWorkspaceDidLaunchApplicationNotification events as desired
When I build and run my Objective-C project—consisting of the files main.m, BNRLogger.h, and BNRLogger.m—in Xcode, the function appLaunch: is supposed to be executed whenever a non-background application without the LSUIElement key in its Info.plist file launches on my MacBook. But that doesn't appear to be happening; the message "An app has started up!" doesn't show up in the Xcode console when an app (e.g., Blender) launches. What's going on? Have I failed to ensure that appLaunch: is called when an NSWorkspaceDidLaunchApplicationNotification is posted, or is no such notification being posted when an app launches? This is what main.m looks like: #import <Cocoa/Cocoa.h> #import "BNRLogger.h" int main(int argc, const char * argv[]) { @autoreleasepool { BNRLogger *logger = [[BNRLogger alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:logger selector:@selector(appLaunch:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]; [[NSRunLoop currentRunLoop] run]; } return 0; } BNRLogger.h looks like this: #import <Foundation/Foundation.h> #ifndef BNRLogger_h #define BNRLogger_h @interface BNRLogger : NSObject @end #endif And here are the contents of BNRLogger.m: #import "BNRLogger.h" @interface BNRLogger () - (void)appLaunch:(NSNotification *)note; @end @implementation BNRLogger - (void)appLaunch:(NSNotification *)note { NSLog(@"An app has started up!"); } @end
1
0
559
Aug ’23