Re-registering a LaunchAgent does nothing

I have an application which uses Service Management framework to register a LaunchAgent. The LaunchAgent registers a mach service with a specific name and it listens for connections made by my application. Also the agent is registered relative to the app bundle using BundleProgram parameter in the agent plist.

My problem is that after the initial registration the service always points to the path where my app bundle was located in the time of registration.

Here is an example:

I download my app from the AppStore and it places it in the /Applications directory. I open it and my service is registered. Then when I want to develop/debug/etc.. from Xcode I build the same app with the same service and I re-register the service from my Debug build and the service still points to the service in the /Applications directory.

I tried the use case when I have two builds of my app with a different CFBundleVersion. The LaunchAgent version was the same as the version which made the initial registration, i.e. no matter which app version I use and that I re-register my service, still the initial registered version of the service is used.

Based on the documentation in SMAppService.h:

If an app updates either the plist or the executable for a LaunchAgent or LaunchDaemon, the SMAppService must be re-registered or it may not launch. It is recommended to also call unregister before re-registering if the executable has been changed.

I think that re-registering the application should work in the aforementioned use cases.

The only workaround I have found so far is:

  1. delete the application which made the initial registration of the service
  2. log out
  3. log in and open the desired app version and register the service with that version.

Does anyone have the same problem and is there a more correct way to handle this use case? Is there a problem in the way I'm using the ServiceManagement framework? Should I write a feedback report to Apple about this problem?

Replies

Should I write a feedback report to Apple about this problem?

Yes.

I haven’t exercised this stuff systematically myself, but I’ve definitely seen some weird stuff. If you have specific steps that you think should work and don’t, that’s definitely bugworthy.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

FB13570494