XPCService not starting from application

I am trying to create an example of a simple application on XPCServices in which I do the following steps:

Step 1: Created a sample project and added a target - XPCServices named - HelperProcess to it. When the target is created, Xcode automatically generates the files below:

  • HelperProcessProtocol.h
  • HelperProcess.h
  • HelperProcess.m
  • main.m

Step 2: A main.m added to main.m in the ServiceDelegate implementation:

 - (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection { // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection. NSLog(@"Log which is never displayed :("); // Configure the connection. // First, set the interface that the exported object implements. newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)]; // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object. HelperProcess *exportedObject = [HelperProcess new]; newConnection.exportedObject = exportedObject; // Resuming the connection allows the system to deliver more incoming messages. [newConnection resume]; // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO. return YES; } 

Step 3: In AppDelegate , the code below is added in applicationDidFinishLaunching:

 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application _connectionToService = [[NSXPCConnection alloc] initWithServiceName:@"HelperProcess"]; _connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)]; [_connectionToService resume]; } 

The problem is

When I launch the application, neither the log added to the listener: shouldAcceptNewConnection: is displayed or the assistant process appears in the Activity Monitor: (

Here is the code: XPCShootOut

Note: I am trying to do this on Xcode 6.0

Is there any additional tweak I need to make it work? Please suggest.

- Update -

I tried passing this sample from apple: AppSandboxLoginItemXPCDemo

When I tried to run it on Xcode 6, it displayed an error message - "Subscription ID not found". Since I do not have a registered mac developer account, in the build settings for iDecide and iDecideHelper, I changed "Code Signature Identification" to "Do not enter code."

I received a warning for each of the goals:

 Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it. 

This time, when I compiled the assembly, it worked as expected.

Now I tried to follow the steps specified in the ReadMe.txt file, in particular, I followed these steps in my sample application:

Step 1: Updated - The main goal of the application β†’ Features tab

  • Application Sandbox Enabled
  • Enabled Application Groups
  • Added application group - "XYZ"

Step 2: Updated - Assistant Goal β†’ Features tab

  • Application Sandbox Enabled
  • Enabled Outgoing Connections (Client)
  • Enabled Application Groups
  • Added application group - "XYZ"

Step 3: Updated - Target β†’ General tab β†’ Package Identifier, added the prefix "XYZ".

When the application was launched in the console, it displayed the following messages:

 10/12/14 6:27:42.159 PM xpcd[554]: (null): Code identity[pid: 11875::Devarshi-Kulshreshtha.XPCShootOut (/Users/devarshi/Library/Developer/Xcode/DerivedData/XPCShootOut-aaedwraccpinnndivoaqkujcmhmj/Build/Products/Debug/XPCShootOut.app)] is not in ACL for container: ~/Library/Containers/Devarshi-Kulshreshtha.XPCShootOut/Data -- allowing access. 10/12/14 6:27:43.712 PM appleeventsd[63]: <rdar://problem/11489077> A sandboxed application with pid 11875, "XPCShootOut" checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013 { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." } (handleMessage()/appleEventsD.cp #2072) client-reqs-q 

None of the applications performed their intended function, and did not display the log message added to the delegate listener:shouldAcceptNewConnection:

I dont know. Please suggest if I missed something? Is it possible to get an example XPC service application without a registered Mac developer account?

+6
source share
1 answer

I do not think that you can start XPC services without signing them.

Even for testing and debugging, the code building infrastructure needs to be customized.

I think the Mac Developer Certificate is free, you don’t need a paid account.

-1
source

Source: https://habr.com/ru/post/976550/


All Articles