题记:
第一次接触MAC的开发.....
Dock也是第一次听说,但弄明白后,这个东西就类似windows的任务栏。
这个Dock可以挂载一个叫NSDockTilePlugIn的
bundle,开发这个类似很多OSGI模型开发bundle一样,继承NSDockTilePlugIn,然后你实现相应的methods,完之后build出来放到指定的目录下,然后在某个特定的“动作”的时候会自动调用这些methods。
The principal class of the plug-in must implement the NSDockTilePlugIn protocol. The setDockTile: method is the only required method in this protocol. When the plug-in is loaded, an object of the principal class is instantiated, and its setDockTile: method is called. The call to this method provides an NSDockTile object to your plug-in. Your plug-in should retain the Dock tile object and perform any other initialization required by your plug-in. For example, if your plug-in receives information from a background-only application, it can register for a notification event sent by that other application.
Your Dock tile plug-in continues to run as long as your application’s tile is in the Dock, even if your application is actually running. Apple recommends that you update your Dock tile in either the application or the plug-in, but not both at the same time. Your application can continue to update the Dock tile inside your plug-in by having the plug-in receive notifications from your application. If both the application and the plug-in update the dock tile, the application takes precedence.
When your application is removed from the Dock, the setDockTile: method is called with a nil parameter. Your setDockTile: method should release the Dock tile object, clean up any resources your Dock Tile plug-in allocated, and exit.
这段主要内容是:
1,build后的bundle必须放到你app下的Contents/PlugIns下,且必须在property list文件中申明,其中内容为.docktileplugin结尾的插件名。
2,插件必须扩展NSDockTilePlugI,当插件加载的时候, setDockTile方法就会被执行,并且返回一个NSDockTile,你可以在这里做些其他初始化工作。
3,你的插件和主程序可以同时updateDock title,但主程序的优先级更高。
4,当你的application 从dock去除的时候,会把NSDockTile指向nil,在Object-C中指向nil的对象是自动释放内存并把指针指向NULL。
Dock Plugin 主要做几个工作:
1,其中更改dock上application的图标。
myView = [[[MyViewClass alloc] init] autorelease];
[[NSApp dockTile] setContentView: myView];
When the Dock icon needs to be updated, you instruct the Dock to update the icon by calling the dock tile object’s display method.
[[NSApp dockTile] display];
2,更改badge:
[[myWindow dockTile] setBadgeLabel:@"42"];
3,定义自己的menu:
问题1:
Apple的官方文档说.docktileplugin要放到Contents/PlugIns目录下,可实现起来未必,我实践的时候放到了Resources目录下。
问题2:
设定Info.plist的时候注意key放到大概第一个<dict>下,类似:<dick><key>xxx</key><string>yyy</string></dick>
Good Luck:)