Mac OS X daemon using Objective-C - launchd
Asked Answered
L

2

11

I'm new in Mac OS X world but I have skills on Windows dev.

I need to develop a daemon (on Windows will be Windows Service) that uploads/downloads files from a Web Service.

My question is: is it possible to create an app written in Objective-C that will be the daemon (to upload/download) and to launch it when the OS starts using launchd? Or there's another way to create a daemon?

Thank you

Lone answered 8/5, 2012 at 22:57 Comment(0)
C
2

I don't know if I have understood correctly but I guess you can do it. The next link could be a good start for understand how Daemons work in Objective-C Apple Developer Then here there is a interesting piece of code. It is about GPS but it might be usefull. Also get a look of this github folder.It is a controller for start/stop daemons

Ceres answered 9/5, 2012 at 8:20 Comment(1)
Thank you, that's something that I'm looking for.Lone
E
4

On OS X these services are called LaunchDaemon (system-wide) and LaunchAgent (user-specific). You create a configuration which tells the system when to start, which executable to run, what to do with stdin, stdout, and stderr, which arguments to pass, and so on. Have a look at these man pages:

launchd(8)       # the service controlling other services
launchctl(1)     # the command to control services
launchd.plist(5) # the configuration format for services

The daemon can be written in any language that runs on OS X. So Objective-C is a typical choice for the Mac platform, but anything else from Ruby, Python, and Perl over AppleScript to plain C or C++ would do.

And no, there is no other (recommended) way to do this on the Mac. init.d-style scripts don't work on the Mac [or on Darwin, it's UNIX layer]. Or, more precisely, there is not the infrastructure that runs them.

For more info see the Daemons and Services Programming Guide.

Exterritorial answered 9/5, 2012 at 8:2 Comment(1)
Emphasis: can be written in any language. Should not use Obj-C for a LaunchDaemon or system-level LaunchAgent because of InputManager hacks!Centuplicate
C
2

I don't know if I have understood correctly but I guess you can do it. The next link could be a good start for understand how Daemons work in Objective-C Apple Developer Then here there is a interesting piece of code. It is about GPS but it might be usefull. Also get a look of this github folder.It is a controller for start/stop daemons

Ceres answered 9/5, 2012 at 8:20 Comment(1)
Thank you, that's something that I'm looking for.Lone

© 2022 - 2024 — McMap. All rights reserved.