My helper agent app needs to constantly perform one activity after its launch, but it also needs to communicate via XPC, to the main app
However, the setup of the listener requires a specific main function, and that takes over the app (omitting the standard AppDelegate NSApplication approach)
int main(int argc, const char *argv[])
{
NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName:bundleId];
XX *xx = [XX new];
listener.delegate = xx;
[listener resume];
return 0;
}
How to have both? Background app with NSRunLoop and NSXPCListener app?
NSApplication is part of the AppKit framework. So if you write a command line tool as agent, you can't use this. But you can of course still us NSRunLoop. Simply start a runloop with
[[NSRunLoop currentRunLoop] run];
. Adding this after your[listener resume]
should keep the process up and running.