I need to write a Mach Service that both my app and a system plugin can talk to, I use the NSMachPort API to create a new port, then register it with NSMachBootstrapServer:
- (void) run
{
NSMachPort *serverPort = (NSMachPort *)[NSMachPort port];
[serverPort setDelegate:self];
[serverPort scheduleInRunLoop:NSRunLoop.currentRunLoop forMode:NSDefaultRunLoopMode];
[NSMachBootstrapServer.sharedInstance registerPort:serverPort name:@"com.example.MyApp"];
[NSRunLoop.currentRunLoop run];
}
Clang complains that NSMachBootstrapServer has been deprecated:
warning: 'NSMachBootstrapServer' is deprecated: first deprecated in macOS 10.13 - Use NSXPCConnection instead
How does one use NSXPCConnection to replace the functionality of NSMachBootstrapServer when writing a non-XPC mach service?
That's true:
NSMachBootstrapServerclass and the majority of its companion classes are deprecated in macOS 10.13 High Sierra.Here's how a XPC Connection process looks like:
And as you can see on a picture, you have to implement a listener.
Here's how a Swift code snippet with listener might look like:
Here's how an Obj-C code snippet with listener might look like:
and...