Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:08:09+00:00 2026-06-18T04:08:09+00:00

The Daemons and Services Programming Guides tells that it is possible to return a

  • 0

The Daemons and Services Programming Guides tells that it is possible to return a proxy object through an open XPC connection, even as a reply block parameter.

Passing an Object By Proxy

Most of the time, it makes sense to copy objects and send them to the other side of a connection. However, this is not always desirable. In particular:

If you need to share a single instance of the data between the client application and the helper, you must pass the objects by proxy.
If an object needs to call methods on other objects within your application that you cannot or do not wish to pass across the connection (such as user interface objects), then you must pass an object by proxy—either the caller, the callee (where possible), or a relay object that you construct specifically for that purpose.
The downside to passing objects by proxy is that performance is significantly reduced (because every access to the object requires interprocess communication). For this reason, you should only pass objects by proxy if it is not possible to pass them by copying.

You can configure additional proxy objects similarly to the way you configured the remoteObjectInterface property of the initial connection. First, identify which parameter to a method should be passed by proxy, then specify an NSXPCInterface object that defines the interface for that object.

First questions come: how should the object to be passed by proxy be defined? As an object conforming to NSXPCProxyCreating protocol? Should remoteObjectProxy and remoteObjectProxyWithErrorHandler: method be implemented then?

An example follows, that is not clear at all to me. In particular I don’t understand where should I call the NSXPCInterface method (setInterface:forSelector:argumentIndex:ofReply:) to whitelist the parameter as a proxy: in the XPC service code or in the host?

The first parameter to a method is parameter 0, followed by parameter 1, and so on.

In this case, the value NO is passed for the ofReply parameter because this code is modifying the whitelist for one of the parameters of the method itself. If you are whitelisting a class for a parameter of the method’s reply block, pass YES instead.

So the question is: can anybody provide me with a clear tutorial on how to return an object as a proxy in a block reply of a XPC method call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:08:11+00:00Added an answer on June 18, 2026 at 4:08 am

    I can answer my own question now: to return an object as a proxy in a block reply of a XPC method call, one should call the setInterface:forSelector:argumentIndex:ofReply: method both:

    • in the XPC service’s endpoint, where the exportedInterface is declared
    • in the host, where the remoteObjectInterface is declared

    I.e, common code:

    // common (service/host) protocol definition
    @protocol Service
    @end
    
    @protocol ServiceFactory
    -(void)connectToNewService: (void (^)(id<Service>)reply;
    @end
    

    In the XPC Service:

    // Implement the one method in the NSXPCListenerDelegate protocol.
    -(BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection*)newConnection {   
    
        NSXPCInterface *serviceFactoryInterface =[NSXPCInterface interfaceWithProtocol:@protocol(ServiceFactory)];
        NSXPCInterface *serviceInterface =[NSXPCInterface interfaceWithProtocol:@protocol(Service)];
    
        // connection has to be returned as proxy, not as a copy
        [serviceFactoryInterface setInterface: serviceInterface
                              forSelector: @selector(connectToNewService:)
                            argumentIndex: 0
                                  ofReply: YES];
    
        newConnection.exportedInterface = serviceFactoryInterface;
        newConnection.exportedObject = self;
    
        [newConnection resume];
        return YES;
    
    }
    

    In the host code:

    // in the host
    
    - (void)openNewService
    {
        NSXPCConnection *xpcConnection = [[NSXPCConnection alloc] initWithServiceName:@"eu.mycompany.servicefactory"];
        NSXPCInterface *serviceFactoryInterface =[NSXPCInterface interfaceWithProtocol:@protocol(ServiceFactory)];
        NSXPCInterface *serviceInterface =[NSXPCInterface interfaceWithProtocol:@protocol(Service)];
    
        // connection has to be returned as proxy, not as a copy
        [serviceFactoryInterface setInterface: serviceInterface
                              forSelector: @selector(connectToNewService:)
                            argumentIndex: 0
                              ofReply: YES];
    
        xpcConnection.remoteObjectInterface = serviceFactoryInterface;
        [xpcConnection resume];
    
        [[xpcConnection remoteObjectProxy] connectToNewService:^(id<Service> newService) {
    
            // here a newService is returned as NSXPCDistantObject <Service>*
            [xpcConnection invalidate];
    
        }];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen lately a couple of programs that can be launched as daemons
Anyone knows or have used Monit::HTTP module for perl connection to monit daemon through
On Windows it is possible to have a service that allows clients running in
I maintain GPSD, a widely-deployed open-source service daemon that monitors GPSes and other geodetic
Say you were writing a daemon that services a job queue. Various other software
I noticed that Controller object is creating each time when I call method in
I have multiple daemons (one gateway and multiple service, all running on same node)
I have a few servers and other daemons I need to start up in
Let's say i have 15 processes/daemons running in the background. let's say one of
I'm technically savvy but don't have extensive experience with servers/daemons (I'm a Windows guy,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.