NSXPCConnection between app and EndPoint Security system extension

Hello,
I have implemented an Endpoint Security system extension with the NSEndpointSecurityMachServiceName property.
My app is able to connect to the extension using initWithMachServiceName and is able to run the functions exported by the extension.
But the reverse produces a strange error in the app process:

<NSXPCConnection: 0x12f924aa0> connection to service on pid 30174 named a.b.c.d.e.f: Exception caught during decoding of received selector hello, dropping incoming message.
Exception: <NSXPCDecoder: 0x10b909600> received a message or reply block that is not in the interface of the remote object (hello), dropping.
(
0  CoreFoundation           0x00007fff205f56af __exceptionPreprocess + 242
1  libobjc.A.dylib           0x00007fff2032d3c9 objc_exception_throw + 48
2  Foundation             0x00007fff212c73e4 -[NSXPCDecoder __decodeXPCObject:allowingSimpleMessageSend:outInvocation:outArguments:outArgumentsMaxCount:outMethodSignature:outSelector:isReply:replySelector:interface:] + 2244
3  Foundation             0x00007fff21312001 -[NSXPCDecoder _decodeMessageFromXPCObject:allowingSimpleMessageSend:outInvocation:outArguments:outArgumentsMaxCount:outMethodSignature:outSelector:interface:] + 33
4  Foundation             0x00007fff21310e3b -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 418
5  Foundation             0x00007fff212c8d49 message_handler + 206
6  libxpc.dylib            0x00007fff201c6c28 _xpc_connection_call_event_handler + 56
7  libxpc.dylib            0x00007fff201c5a9c _xpc_connection_mach_event + 935
8  libdispatch.dylib          0x00007fff202d8867 _dispatch_client_callout4 + 9
9  libdispatch.dylib          0x00007fff202efa47 _dispatch_mach_msg_invoke + 441
10 libdispatch.dylib          0x00007fff202de4a7 _dispatch_lane_serial_drain + 263
11 libdispatch.dylib          0x00007fff202f05b8 _dispatch_mach_invoke + 498
12 libdispatch.dylib          0x00007fff202de4a7 _dispatch_lane_serial_drain + 263
13 libdispatch.dylib          0x00007fff202df0fe _dispatch_lane_invoke + 426
14 libdispatch.dylib          0x00007fff202e8c5d _dispatch_workloop_worker_thread + 819
15 libsystem_pthread.dylib       0x00007fff20480499 _pthread_wqthread + 314
16 libsystem_pthread.dylib       0x00007fff2047f467 start_wqthread + 15
)

The "hello" function called from the extension is logically in the interface of the local object (the app). Why should it be in the interface of the remote object (the extension)?

hello is a very simple function:
  • (void)hello;

Any idea to make it work?
Thank you.
Chris
Answered by chrilarc in 673664022
Problem solved. It was due to 2 different structures with the same name.
The approach I usually use here is to have the client (the app in this case) create an anonymous listener, grab an endpoint from that, and then pass that endpoint over to the server (your ES sysex). The server can then open a connection to that endpoint, after which everything just works but in reverse (-:

For more info on this, see this post. That also discusses a gotcha that you’ll need to think about, and a later post on the same thread discusses a nice way to address that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Thank you for your answer.
But doing what you explained, the error is nearly the same.

<NSXPCConnection: 0x12d834ab0> connection on anonymousListener or serviceListener from pid 36952: Exception caught during decoding of received selector hello, dropping incoming message.
Exception: <NSXPCDecoder: 0x10c9e6000> received a message or reply block that is not in the interface of the remote object (hello), dropping.
(
0  CoreFoundation           0x00007fff205f56af __exceptionPreprocess + 242
1  libobjc.A.dylib           0x00007fff2032d3c9 objc_exception_throw + 48
2  Foundation             0x00007fff212c73e4 -[NSXPCDecoder __decodeXPCObject:allowingSimpleMessageSend:outInvocation:outArguments:outArgumentsMaxCount:outMethodSignature:outSelector:isReply:replySelector:interface:] + 2244
3  Foundation             0x00007fff21312001 -[NSXPCDecoder _decodeMessageFromXPCObject:allowingSimpleMessageSend:outInvocation:outArguments:outArgumentsMaxCount:outMethodSignature:outSelector:interface:] + 33
4  Foundation             0x00007fff21310e3b -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 418
5  Foundation             0x00007fff212c8d49 message_handler + 206
6  libxpc.dylib            0x00007fff201c6c28 _xpc_connection_call_event_handler + 56
7  libxpc.dylib            0x00007fff201c5a9c _xpc_connection_mach_event + 935
8  libdispatch.dylib          0x00007fff202d8867 _dispatch_client_callout4 + 9
9  libdispatch.dylib          0x00007fff202efa47 _dispatch_mach_msg_invoke + 441
10 libdispatch.dylib          0x00007fff202de4a7 _dispatch_lane_serial_drain + 263
11 libdispatch.dylib          0x00007fff202f05b8 _dispatch_mach_invoke + 498
12 libdispatch.dylib          0x00007fff202de4a7 _dispatch_lane_serial_drain + 263
13 libdispatch.dylib          0x00007fff202df0fe _dispatch_lane_invoke + 426
14 libdispatch.dylib          0x00007fff202e8c5d _dispatch_workloop_worker_thread + 819
15 libsystem_pthread.dylib       0x00007fff20480499 _pthread_wqthread + 314
16 libsystem_pthread.dylib       0x00007fff2047f467 start_wqthread + 15
Accepted Answer
Problem solved. It was due to 2 different structures with the same name.
NSXPCConnection between app and EndPoint Security system extension
 
 
Q