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

Table of Contents

Issue

I have a few questions regarding daemons. Indeed, even the macos developer center has limited information resources.

I want to develop an application daemon that runs after system boot without login.

a) 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?

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.

c) 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?

I would be very happy to hear your suggestions.

Solution

I’ve made a launch daemon in the past, for the purpose of making a privileged helper tool with SMBless. I can share some of my experience.

A

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?

Here are some resources that I found useful:

  1. Woody’s Cocoa: implement a privileged Helper. This article covers the low-level, step by step process of making a launch daemon and launching it as a privileged helper tool. If you have no need for privileged execution, the steps would be much the same, but without the SMJobBless parts.
  2. SwiftAuthorizationSample which show cases SecureXPC (a framework for Swifty, Codable-based XPC communication) and Blessed (a framework for a Swifty, modern interface to SMJobBless and the AuthorizationServices framework). It handles a lot of the complexity from #1.
  3. Apple’s 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.

No. You would distribute them as part of an app, and make your app install them when required.

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 certainly, but I’m not sure about the screen capture APIs. One of the differences between launch agents and daemons (IIRC), is that only launch agents can connect to the window server, which I assume is necessary for the screen capture APIs.

From 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:

Answered By – Alexander

Answer Checked By – Gilberto Lyons (BugsFixing Admin)

Leave a Reply

Your email address will not be published.