I have some code in my Mac app that performs a long-running export operation. At the end of the export, it creates a user notification to let the user know it's finished:
- (NSUserNotification*)deliverNotificationWithSound:(NSString*)sound title:(NSString*)title messageFormat:(NSString*)message {
NSUserNotification * note = [NSUserNotification new];
note.soundName = sound;
note.title = title;
note.informativeText = [NSString stringWithFormat:message, NSRunningApplication.currentApplication.localizedName, self.document.displayName];
note.userInfo = @{ @"documentFileURL": self.document.fileURL.absoluteString };
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:note];
return note;
}
It then puts a sheet up with details about the export (warnings encountered, a handy "Reveal" button, etc.). When they dismiss the sheet, I want to remove the notification, like so:
[NSUserNotificationCenter.defaultUserNotificationCenter removeDeliveredNotification:note];
However, this doesn't actually remove the notification from Notification Center. I've set a breakpoint; the -removeDeliveredNotification:
line is run, and note
is not nil. What gives?