I feel like I am going insane here.
I'm making a little command-line tool to let me know when a Twitch channel I like goes live. So far, everything works. There's only one, small issue: [NSUserNotificationCenter defaultUserNotificationCenter]
is consistently returning nil
, no matter where I call it in the program. This is a bit of a problem, since I need to be able to send notifications.
After a solid hour of googling, I can't figure out what's going on. Something like [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:myDelegate]
doesn't crash, but I'm pretty sure that's because you can send messages to nil
in Obj-C. Similarly, I can do something like [[NSUserNotificationCenter defaultNotificationCenter] deliverNotification: mynote]
, but nothing is displayed onscreen (and this is with the delegate for [NSUserNotificationCenter defaultUserNotificationCenter]
set to return YES
for the userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)
method.)
Additionally, all notifications presented via deliverNotification
do not have their delivered
property set to YES.
The only thing I can think of is that the usage of NSUserNotificationCenter
only works if you're running an NSApplication
, but I cannot find that documented anywhere. I'm running a simple command-line tool, which is pretty much a main
function, an @autoreleasepool
, and some method calls.
Is there anything obvious that can cause [NSUserNotificationCenter defaultUserNotificationCenter]
to return nil?