论坛首页 综合技术论坛

About Dock Plugin on Mac

浏览 2150 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-11-21   最后修改:2010-11-24

题记:

     第一次接触MAC的开发.....

 

    Dock也是第一次听说,但弄明白后,这个东西就类似windows的任务栏。

    这个Dock可以挂载一个叫NSDockTilePlugIn的 bundle,开发这个类似很多OSGI模型开发bundle一样,继承NSDockTilePlugIn,然后你实现相应的methods,完之后build出来放到指定的目录下,然后在某个特定的“动作”的时候会自动调用这些methods。

 

 

写道
The Dock tile plug-in must be placed inside the Contents/PlugIns directory of your application’s package. The plug-in is associated with the application by adding a NSDockTilePlugIn key to the application’s information property list. The value associated with this key is the name of the plug-in’s bundle, which must end with a .docktileplugin extension.

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的图标。

写道
Dock tile icons can be customized using an NSView object. This is useful if your application needs to dynamically generate Dock tile icons at run time. To provide a custom view, you instantiate a new view object, retrieve the dock tile object from the application or window object, and set your view as its contentView.

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:

写道
The dock tile object can overlay a short text message on top of the Dock icon. To change the badge label, you call the Dock tile’s setBadgeLabel: method.

[[myWindow dockTile] setBadgeLabel:@"42"];

 

    3,定义自己的menu:

写道
Your class can optionally provide a dockMenu method to provide additional custom menu items. This method works similarly to the applicationDockMenu: method provided by the application delegate. Mac OS X calls your plug-in’s dockMenu method when the user requests the menu for your Dock tile.

 

 

问题1:

    Apple的官方文档说.docktileplugin要放到Contents/PlugIns目录下,可实现起来未必,我实践的时候放到了Resources目录下。

问题2:

    设定Info.plist的时候注意key放到大概第一个<dict>下,类似:<dick><key>xxx</key><string>yyy</string></dick>

Good Luck:)

 

详情:http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/customizing_docktile/CreatingaDockTilePlug-in/CreatingaDockTilePlug-in.html#//apple_ref/doc/uid/TP30000986-CH4-SW1

论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics