问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/52469199/mac-how-to-save-alternate-app-icon-in-dock-osx-xcode