macOS 守护进程应该由 "Command Line Tool" Xcode 模板制作吗?

Should macOS daemons be made from the "Command Line Tool" Xcode template?

我有几个关于守护进程的问题。确实,连macos开发者中心的信息资源都有限

我想开发一个无需登录即可在系统启动后运行的应用程序守护进程。

a) 一个守护进程;它是一个结合了 plist 的简单控制台应用程序吗?因为几乎没有Xcode相关的daemon开发教程。如果有代码示例参考,能分享一下吗?

b) 守护进程可以从应用商店下载吗?因为必须有一个软件,我可以通过 App Store 提供给每个人。是否像其他应用商店应用一样自动安装?如果哪位有经验可以分享一下,不胜感激

c) 我正在研究与将屏幕镜像到 Android phone 有关的 API。您认为守护进程可以完全访问 WiFi/BLE 和屏幕截图 APIs 吗?

我很乐意听取您的建议。

我过去做过一个启动守护进程,目的是用 SMBless 制作一个特权帮助工具。我可以分享一些我的经验。

一个

a Daemon; Is it a simple console application combined with a plist? Because there are almost no tutorials on daemon development related to xcode. If there is a code sample reference, can you share it here?

以下是我认为有用的一些资源:

  1. 伍迪 Cocoa: implement a privileged Helper。本文涵盖了 low-level 制作启动守护进程并将其作为特权帮助工具启动的分步过程。如果您不需要特权执行,步骤将大致相同,但没有 SMJobBless 部分。
  2. SwiftAuthorizationSample which show cases SecureXPC (a framework for Swifty, Codable-based XPC communication) and Blessed(SMJobBless 和 AuthorizationServices 框架的 Swifty 现代接口框架)。它处理了#1 中的很多复杂性。
  3. 苹果的Daemons and Services Programming Guide

B

Can daemons be downloaded from the app store? Because there must be a software that I can offer to everyone through the app store. Is the installation automatic like other app store apps? If anyone has experience and can share it, I would be very grateful.

没有。您可以将它们作为应用程序的一部分进行分发,并在需要时让您的应用程序安装它们。

I am working on an api related to mirroring the screen to android phone. Do you think a daemon has full access to WiFi/BLE and screen capture APIs?

肯定是 WiFi,但我不确定屏幕捕获 API。启动代理和守护进程 (IIRC) 之间的区别之一是只有启动代理可以连接到 window 服务器,我认为这是屏幕捕获 API 所必需的。

来自 Technical Note TN2083 – Daemons and Agents:

Daemons

A daemon is a program that runs in the background as part of the overall system (that is, it is not tied to a particular user). A daemon cannot display any GUI; more specifically, it is not allowed to connect to the window server. A web server is the perfect example of a daemon.

...

Agents

An agent is a process that runs in the background on behalf of a particular user. Agents are useful because they can do things that daemons can't, like reliably access the user's home directory or connect to the window server. A calendar monitoring program is a good example of an agent because: