-
Notifications
You must be signed in to change notification settings - Fork 41
/
NSBundle+AppIcon.m
23 lines (19 loc) · 942 Bytes
/
NSBundle+AppIcon.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#import "NSBundle+AppIcon.h"
#import "NSBundle+MainApp.h"
@implementation NSBundle (AppIcon)
- (NSString*)appIconPath {
// Oddly, I can't find a constant for the bundle icon file.
// Compare to kCFBundleNameKey, which is apparently "CFBundleName".
NSString* iconFilename = [[NSBundle mainAppBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"] ;
// I do not use -pathForImageResource, in case the Resources also contains
// an image file, for example a png, with the same name. I want the .icns.
NSString* iconBasename = [iconFilename stringByDeletingPathExtension] ;
NSString* iconExtension = [iconFilename pathExtension] ; // Should be "icns", but for some reason it's in Info.plist
return [[NSBundle mainBundle] pathForResource:iconBasename
ofType:iconExtension] ;
}
- (NSImage*)appIcon {
NSImage* appIcon = [[NSImage alloc] initWithContentsOfFile:[self appIconPath]] ;
return [appIcon autorelease] ;
}
@end