I am using runtime loaded dynamic libraries (in an NSBundle) as a plugin system in my app.
I would like to switch over to using XPC Services though, for various reasons.
Is it possible to load plugins which are really xpc services from a user-specified folder?
I have not yet figured out how I would go about dicovering that a plugin is present or put in the PlugIns folder.
That folder would most likely be either under ~/Documents/MyApp/PlugIns or something else user-accessible.
(I may also ship some plugins with the app, which are inside the app's bundle, but discovering/loading those seems trivial)
Thank you for your help.
Thomas
Is it possible to load plugins which are really xpc services from a user-specified folder?
No.
One alternative that’s relatively straightforward is to have a single XPC Service that loads all your plug-ins.
Unfortunately there’s no public API for creating an XPC Service that you can instantiate multiple times (although that’d make a fine enhancement request). It may be possible to simulate that by using a parent XPC Service with a bunch of child processes, one for each plug-in, but I’ve never sat down to write the code to confirm that this works.
Finally, Apple has internal infrastructure — known as PlugInKit, hence the
pluginkit
command-line tool — that was specifically designed for this sort of thing. Indeed, it’s what the various app extensions are built around. Making a public API from this would be another fine
enhancement request.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"