12

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?

Volomike
  • 23,743
  • 21
  • 113
  • 209
kalikkalik
  • 187
  • 8

1 Answers1

4

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

CodaFi
  • 43,043
  • 8
  • 107
  • 153