Application exposing an API

I'm sorry if this isn't in the right place in the forums.


How could my macOS application expose an API for other macOS applications to use? I want other applications to be able to send data to my application, and my application will take care of storing that data. During development, I also want to be able to manually interact with my application via its API, eg by typing in commands.

Replies

What you are describing seems to fit the description of a Launch Agent, or Launch Daemon. There are guides in the Apple documentation on how to build a launch agent or launch daemon. Launch agents can even have a GUI (I think). Nice thing about agents and daemons is that can be started up by the system on demand, you don't have to start it manually.

How could my macOS application expose an API for other macOS applications to use?

Are you targeting the Mac App Store? Or distributing independently using Developer ID?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm targeting the Mac App Store.

Thanks, I'll look at that.

I'm targeting the Mac App Store.

That makes things tricky. In general, Mac App Store apps are not allowed to make changes to the system as a whole, which rules out all the

launchd
options.

I can see two feasible here:

  • Apple events — If you make your app scriptable, other apps can request that you do work by sending you Apple events.

  • TCP/IP — Mac App Store apps are allowed to opening listening sockets, assuming you apply the

    com.apple.security.network.server
    entitlement. There’s a couple of gotchas here. The obvious one is security: You don’t want your app accepting requests from across the network. The less obvious one is App Review. My experience is that they look carefully at apps with the
    com.apple.security.network.server
    to ensure that they provide some obvious user-level server feature.

If I were in your shoes, I’d do the Apple events thing.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks very much. I'll give Apple events a go.

Have you looked into an AppleScript dictionary?