0

I need to know how to create an application which will always be running in the background and collects location info once every 10 minutes. I don't know much about launch agents and daemons.

I have read a few examples where I found Launch agents is just a plist file. Should we launch the app through launch agents every 10 minutes? How to do that?

Ankur Prakash
  • 1,417
  • 4
  • 18
  • 31

1 Answers1

3

There's no simple answer to this; you really need to read—or at least familiarize yourself with—the Daemons and Services Programming Guide, particularly the "Creating Login Items" section.

If you plan on creating a sandboxed (App Store) application, that limits your options somewhat, but not dramatically (for this kind of application).

You need to decide if your background process needs a UI or not. I suspect not, so I'd direct you to the either the XPC Service or user agent route. These will be registered with launchd and launchd has about a billion different options for how and when your process gets launched, and one of those is periodically. For more info on those, see man launchd.plist, particularly StartInterval and StartCalendarInterval.

With this knowledge, I'd then suggest to do some internet and open source searches looking for examples. I'm sure you'll find plenty.

James Bucanek
  • 3,299
  • 3
  • 14
  • 30
  • Can you please give any demo example how to make XPC service? how to connect to main app? Tracking location code will be in main cocoa app or XPC service? I don't have any idea about daemons and XPC – Ankur Prakash Jun 02 '19 at 12:03
  • 1
    The tracking would be done by the background service (either a login item, user agent, or XPC Service). Read the first part of the guide ("Types of Background Processes") to decide which one fits your needs. (I'm now thinking a user agent is probably your best bet.) Once you decide the kind of service, follow the detailed, step-by-step, instructions in that section for creating your service. This is complicated stuff. I googled a couple of, very simple, example projects on GitHub; you should be able to do the same. – James Bucanek Jun 02 '19 at 17:22