Mac os上App开机自动启动

  • Post author:
  • Post category:其他


Mac OS上运行的App,想要支持用户登录后App自动启动的功能,可以使用Service Management Framework 或 Shared File List实现。对于沙箱开启的应用,苹果推荐的做法是使用Service Management Framework;对于沙箱未开启的应用,苹果推荐使用Shared File List。Service Management Framework对于沙箱未开启的APP也是可以实现登录后自动启动的。

对于Service Management framework 和 shared file list,苹果的官方解释为:

Login items installed using the Service Management framework are not visible in System Preferences and can only be removed by the application that installed them.

Login items installed using a shared file list are visible in System Preferences; users have direct control over them. If you use this API, your login item can be disabled by the user, so any other application that communicates with it it should have reasonable fallback behavior in case the login item is disabled.

使用Service Management Framework方式添加的登录项不会显示在系统偏好设置->用户与群组->登录项中,只有把应用.app文件移到废纸篓,自动启动才会失效。

使用System Preferences方式添加的登录项会显示在系统偏好设置->用户与群组->登录项中,因此可以勾选隐藏按钮来控制自动启动的功能是否生效。


本文将介绍通过Service Management Framework来实现App自定启动的方法。基本方式是创建一个辅助启动的”Helper Application”,将其注册到系统中,在用户登录后通过它来启动主App。

The Helper App

在工程中添加一个Cocoa Application类型的target。



版权声明:本文为huilibai原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。