NSUserNotification - Mavericks & Custom images
Asked Answered
F

1

11

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?

Footed answered 5/11, 2013 at 20:2 Comment(0)
I
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

Ironist answered 23/3, 2014 at 4:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.