Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

490
Visualizações
NSMachBootstrapServer is deprecated, how can NSXPCConnection be used to register a Mach Service?

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?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

That's true: NSMachBootstrapServer class and the majority of its companion classes are deprecated in macOS 10.13 High Sierra.

In macOS 10.14 Mojave and higher you have to use a NSXPCConnection API, that is the Foundation module's part. It's described in the header file NSXPCConnection.h. At the moment it consists of the four main classes:

  • NSXPCConnection
  • NSXPCInterface
  • NSXPCListener
  • NSXPCListenerEndpoint

Here's how a XPC Connection process looks like:

enter image description here

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:

let listener = NSXPCListener(machServiceName: "Name-of-Sample.Helper")
listener.delegate = delegate
listener.resume()
RunLoop.current.run()

Here's how an Obj-C code snippet with listener might look like:

self.listener = [[NSXPCListener alloc] initWithMachServiceName:@"Name-of-Sample.Helper"];
self.listener.delegate = self;
[self.listener resume];
[[NSRunLoop currentRunLoop] run];

If you look at This Post you'll find out how to properly implement all the necessary XPC Connection's objects.

and...

If you look at This Post you'll also find out how it can be used with a Mach Service (there's GitHub link).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda