Created
November 19, 2011 20:04
-
-
Save indragiek/1379289 to your computer and use it in GitHub Desktop.
Automatically updating NSDockTile with badge count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface AppDelegate : NSObject | |
@property (nonatomic, assign) NSInteger badgeCount; | |
@end | |
@implementation AppDelegate | |
@synthesize badgeCount; | |
// Override the badgeCount setter to update the dock tile whenever the count is set | |
- (void)setBadgeCount:(NSInteger)count | |
{ | |
badgeCount = count; | |
NSDockTile *tile = [NSApp dockTile]; | |
// Show the badge if the count is larger than 0 | |
if (badgeCount) { | |
[tile setShowsApplicationBadge:YES]; | |
// Set the label to a string that shows the numerical value | |
[tile setBadgeLabel:[NSString stringWithFormat:@"%ld", badgeCount]]; | |
} else { | |
[tile setShowsApplicationBadge:NO]; | |
[tile setBadgeLabel:nil] | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you show me an easy example of how to make a simple dock tile app?
I'd like to add an unread count for my Coherence (a chrome wrapper) Google Inbox app.