How to get App Icon


Gerriet M. Denkmann
 

macOS 13.6

The app has Assets.xccassets/AppIcon and shows a nice icon in the dock.

But an NSAlert just shows a boring alert-triangle.
I want it to display the icon of my app instead.

So I did:
NSImage *myAppImage = [ [NSApplication sharedApplication] applicationIconImage ];
NSLog(@"%s myAppImage: %@", __FUNCTION__, myAppImage);

myAppImage: <NSImage 0x60000007cb40 Size={128, 128} Reps=(
"<NSCGImageSnapshotRep:0x608000461b40 cgImage=<CGImage 0x6080001c3de0>\n\t<<CGColorSpace 0x6000000a04e0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Color LCD)>\n\t\twidth = 256, height = 256, bpc = 8, bpp = 32, row bytes = 1024 \n\t\tkCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little \n\t\tis mask? No, has mask? No, has matte? No, should interpolate? Yes>"
)>

[alert setIcon: myAppImage];

And now I get an even more boring default app image (paper with 2 pencils).
I really want the nice app image as shown in the dock.

There must be a simple answer (which becomes immediately obvious once known) to this.


Gerriet.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.