Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSUserNotification - Mavericks & Custom images

In 10.9, NSUserNotification supports a new property "contentImage", which allows the use of a graphic within the notification itself. I was really hoping that there might be a way to usurp the notification screen ala iTunes' notifications, so it would appear as if the sender/bundle app icon is customized.

enter image description here

But it appears that the property only allows for a subset of what I'm looking for, and the contentImage property only handles images thusly:

enter image description here

Any ideas on a workaround?

like image 426
kalikkalik Avatar asked Nov 05 '13 20:11

kalikkalik


1 Answers

NSUserNotification makes no bones about being an extremely closed system. If you're in the market for private APIs, however, NSConcreteUserNotification implements a method called set_identityImage:. Pass that a valid NSImage, and the presented notification lays out its content exactly like that iTunes banner.

@interface NSUserNotification (CFIPrivate)
- (void)set_identityImage:(NSImage *)image;
@end

- (void)applicationDidFinishLaunching:(NSNotification *)notif {
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    notification.title = @"Some Title";
    notification.subtitle = @"Some subtitle";
    [notification set_identityImage:[NSImage imageNamed:@"CF_Logo.png"]];
    [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
}

Custom Banner

like image 106
CodaFi Avatar answered Oct 30 '22 16:10

CodaFi