简体   繁体   中英

Mac: How to save alternate app icon in dock OSX xcode

In xcode on OSX app, I can change the app icon in the dock by using this code:

let image = NSImage.init(named: NSImage.Name(rawValue: "AltAppIcon"))
NSApp.applicationIconImage = image

But when I close the application the dock image reverts back to the original icon. Is there a way I can save the alternate icon so it will show at all times even when the app is closed? Thanks for any help.

You can implement a Dock tile plug-in. Much of the documentation for this has vanished, unfortunately. You can read about loadable bundles generally and plug-ins specifically in the Code Loading Programming Topics .

You would create a new Bundle target in your app project. A Dock tile plug-in's bundle extension must be docktileplugin. You should add a class to that target that adopts and implements the NSDockTilePlugin protocol. Set the NSPrincipalClass key in the bundle's Info.plist to the name of your class.

In the main app target, add the bundle target's product to be copied to the Contents/PlugIns directory in your app's bundle. Also, the app's Info.plist needs to have a key NSDockTilePlugIn whose value is the name of the plugin bundle.

When your plug-in is loaded, the system will call its -setDockTile: method, passing in an instance of NSDockTile for it to use. Your code can use that object to manipulate your app's Dock tile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM