varun
varun

Reputation: 25

App icon is not changing at run time in Mac OSX 10.9.4

I am working on a project, which require to change App icon at runtime. I have set default_icon.icns as default App icon.

Now when i want to change icon of App, I am using below code snippet in Appdelegate.m class.

NSString *iconPath = @“ ICON_PATH/new_icon_file.png ”;
NSImage *icon =[[NSImage alloc] initWithContentsOfFile:iconPath];

if (icon != nil)
{
    NSLog(@“Changing App icon");
    [NSApp setApplicationIconImage:icon];
}

When I run this project on 10.9.4 OSX,App Icon is not changing at run time, until i restart my Mac machine. After restarting mac machine, App default_icon is replaced with new_icon_file.

But above code snippet was working fine till 10.8 Mac OSX, There was no need to restart Mac machine and after executing “[NSApp setApplicationIconImage:icon]” line in code. default_Icon get replaced with new_icon_file.

Please correct me if there is any problem with above code snippet for changing App icon at run time?? or, Is there any other way to Change AppIcon at run time in 10.9 Mac OSX??

Thanks.

Upvotes: 1

Views: 640

Answers (1)

Daij-Djan
Daij-Djan

Reputation: 50099

this method is not meant to change the finder app icon.

the docs state:
"...temporarily change the app icon in the dock app tile."

so if it worked that was a bug / at least unspecified behaviour.


what works is setting the icon for the app dir:

use NSWorkspace
there is - (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath options:(NSWorkspaceIconCreationOptions)options

example of the top of my head
[[NSWorkspace sharedWorkspace] setIcon:[[NSBundle mainBundle] bundlePath] options:0];

Upvotes: 2

Related Questions