设为首页 收藏本站
查看: 857|回复: 0

[经验分享] About Dock Plugin on Mac

[复制链接]

尚未签到

发表于 2016-5-17 12:00:18 | 显示全部楼层 |阅读模式
  题记:
  第一次接触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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-218243-1-1.html 上篇帖子: 在Mac上配置adb命令 下篇帖子: mac ox-s快捷键
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表