1

I'm new to Apple XPC tech(actually I'm also new to Objective-C), recently I want to learn something about XPC technology, which is used to communicate between processes. Does anybody know how to combine a command line hello world program with an XPC program by using XCode? What I did is: 1) Create a command line 'HelloWorld' project; 2) Create a 'target' under the project 'HelloWorld' project; 3) Then I don't know how to combine them together; (maybe be set something in build setting?) If you can show me how to do this, it would be very helpful. Thanks.

My os is 10.12, xcode is 8.2.

Eric Wang
  • 21
  • 1
  • 2

1 Answers1

0

This link has some useful information about what you are looking for.

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingXPCServices.html#//apple_ref/doc/uid/10000172i-SW6-SW1

Adding a XPC service target to your Xcode project should be the only thing you need to do, other than implementing the actual service.

The grunt work is taken care by Xcode itself. If you check the BuildPhase of your app, it will show that there is an Embedded service section which will take care of copying your XPC service output to your build output dir.

Once things compile, you ll find your XPC service is #build/(Debug || Release)//XpcServices

Prasanna
  • 31
  • 2
  • Hi Prasanna, thanks for your comments. I tried, it can compile success, but my app always can't call the XPC success. – Eric Wang Feb 14 '17 at 02:57
  • I create a repo in github and upload my code. Can you help to take a look? I add the XPC calling code in helloworld, but it never works. https://github.com/lelewestlife/HelloWorldXPC – Eric Wang Feb 14 '17 at 03:27
  • The code you posted looks fine to me. What exactly is happening?. Is the XPC service launched. You can use `ps` to see if your service is launched or not. Here is a sample implementation of an XPC service in C. https://github.com/drichardson/examples/blob/master/XPCApplicationExample/XPCMultiplierService/main.m . I tried this and it works fine. – Prasanna Feb 14 '17 at 18:10
  • Thank you! I tried again, it works. It's the setup issue. Thanks for sharing your code. – Eric Wang Feb 24 '17 at 09:29