NSUserNotification - 小牛队&自定义图像

时间:2013-11-05 20:02:19

标签: objective-c icons nsusernotification

在10.9中,NSUserNotification支持新属性“contentImage”,它允许在通知本身内使​​用图形。我真的希望有一种方法可以通过iTunes的通知篡改通知屏幕,所以看起来好像发件人/捆绑应用程序图标是自定义的。

enter image description here

但似乎该属性只允许我正在寻找的子集,而contentImage属性只能处理图像:

enter image description here

关于变通办法的任何想法?

1 个答案:

答案 0 :(得分:4)

NSUserNotification对于一个非常封闭的系统毫不掩饰。但是,如果您在私有API市场中,NSConcreteUserNotification实现了一个名为set_identityImage:的方法。传递一个有效的NSImage,并且呈现的通知的内容与iTunes横幅完全相同。

@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