开发者

Mac daemon howto (by the 'book')

开发者 https://www.devze.com 2023-03-30 09:44 出处:网络
I\'m relatively new to Mac programming, and I need a simple daemon to run in the background. Basically it has to start either when the computer starts or when it\'s GUI counterpart launches, it needs

I'm relatively new to Mac programming, and I need a simple daemon to run in the background. Basically it has to start either when the computer starts or when it's GUI counterpart launches, it needs to be able to re开发者_如何学Goad the NSUserDefaults of its GUI counterpart, and it either needs to be able to display a simple GUI of it's own, or launch the main app to display it. Also, I'm releasing it on the Mac app store, and I've heard theres a special way you have to install something like this, to get the users permission. Does anyone have any information, maybe a tutorial, on how to do this? My Googleing has come up unusually dry in this area...


Technical Note TN2083 is pretty much required reading if you're trying to implement these kinds of things, but hasn't been updated since OS X 10.5; however, it provides some good background and history. Also read Daemons and Services Programming Guide, which covers new APIs in 10.6/10.7 such as the Service Management framework and XPC.

If you need to run when the computer starts (as opposed to when a user logs in), then you'll need to install with authentication as well; you can either (preferably) use authentication inside your app, or use an installer. If you are happy simply running on login, then you can SMLoginItemSetEnabled to create a login item; this is explicitly allowed by the App Store guidelines.

By contrast, both background processes starting at boot and applications that require authentication are disallowed in the Mac App Store. The guidelines aren't publicly available, but if you have a Mac developer membership, read them carefully. Of course, you can do both freely if you distribute your app outside the App Store. You can also choose to make the full-time background aspect of your app an optional download outside the App Store, as long as your App Store app runs fine without it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号