XPC service not as a separate Target but an inbuilt class that implements listener delegate in the app.All examples I see online have separate target that make a xpc service tool and copies it to app resources folder for supporting incoming connections. Is there a way to do it like I want ?
1 Answers
No there isn't.. Sorry to be blunt and spoil your weekend.
XPC's run as a service to something i.e.
YouApp.app
Contents
XPCServices/
SomeService.xpc
Don't let the "xpc" extension fool you, it's noting but an "app" to put it in layman terms.
When the "YouApp.app" fires up, launchd (the big daddy that makes your mac tic) is notified of it and investigations begin.
The reason why launchd is so fussy about them (libxpc) is because they run at a low level and potentially could be harmful, BUT... because they run at allow level, they're extremely nippy and do their job efficiently.
A good example for a beginner to get started with is:
Basically, there's 1 app and 2 XPC services.
and the flow goes as follows:
1) App fires up 2) launchd (amongst other things authorises XPC services to run) 3) the app asks one service to download something off the internet you can enter in the URL 4) that service downloads it, saves it in a place that all the services (and the app) have access too i.e. the Application Group. 5) Then the app asks the other service to "zip" it.
and that's it.
It does take a while to get around at first, and the most frustrating thing is code-signing.
Just a fore-warning. If you want this to run nicely, you'll probably wind up codesiging from the terminal rather than letting XCode it.
Another thing to keep an eye open for is the "schemes". Make sure that you have the XPC debugging settings set correctly or it'll just appear like nothings happening at all
Finally, Console is your friend :D Keep it open when debugging XPX.