我需要编写一个Mach服务,使得我的应用程序和系统插件都可以与之通信。我使用NSMachPort
API创建一个新的端口,然后将其注册到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抱怨NSMachBootstrapServer
已被弃用:
warning: 'NSMachBootstrapServer' is deprecated: first deprecated in macOS 10.13 - Use NSXPCConnection instead
如何使用NSXPCConnection
来替代NSMachBootstrapServer
的功能,在编写非XPC mach服务时?