Login Item failing to launch with SMAppService. Error: 78, LastExitStatus: 19968

I'm having some trouble getting a Login Item to launch at all.

Both the main App and the Login Item are Sandboxed. I'm launching the Login Item with the following call:

try SMAppService.loginItem(identifier: agentBundleID).register()

The call does not fail in any way, and the subsequent status of the login item is "registered", but the login item does not launch.

Then I do:

-> launchctl list | grep myapp                                                                                
-	78	teamid.com.myorg.myapp.agent.debug

and

-> launchctl error 78
78: Function not implemented

and

-> launchctl list teamid.com.myorg.myapp.agent.debug
{
	"EnableTransactions" = true;
	"LimitLoadToSessionType" = "Aqua";
	"MachServices" = {
		"teamid.com.myorg.myapp.agent.debug" = mach-port-object;
	};
	"Label" = "teamid.com.myorg.myapp.agent.debug";
	"OnDemand" = true;
	"LastExitStatus" = 19968;
	"Program" = "teamid.com.myorg.myapp.agent.debug";
};

The LastExitStatus 19968 doesn't tell me a lot. Just that launch services probably is not being able to find my login item for some reason.

Is there anything I can do to try and narrow this down to something I can fix?

I have a different target for our DeveloperID App and Agent (same code different targets), and that combination works just fine. The plist produced is very similar.

See this thread.

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

I managed to resolve my issue to the point where I can at least debug the app. I'm not sure yet if my solution resolves the issue for good, but it's good enough for being able to test.

It was indeed a weird caching issue by macOS.

I'll document it here in hopes that it may help others resolve this issue in the future.

We're developing an app that uses a different target / bundle ID for the developer ID build and the App Store one. Additionally the same applies to the Login Item we're launching, where the same login item has a developer ID target and an App Store target with different bundle IDs.

What caused this issue in the first place?

I believe the trigger for this issue was that when I set up the developer ID build of our App, I added the wrong login item. This caused in our developer ID app being associated with the App Store login item in launchctl.

I changed the agent after realizing the mistake but the App Store Agent would never launch.

How I debugged this

I initially focused on checking the parent app / login item association that you can see by calling:

sfltool dumpbtm

The association returned by that tool was correct, and nothing in it seemed off.

I tried resetting it through sfltool resetbtm, but that didn't work at all.

At some point I started diving deeper into launchctl, and used this command to get a very detailed state report:

launchctl dumpstate > out.txt

And when looking for my agent's bundle ID I realized that launchctl was showing a different association with the wrong parent bundle ID.

The snippet looked more or less like so:

gui/userid/teamid.my.agent.bundle.id = {
	active count = 0
	path = (submitted by smd.299)
	type = Submitted
	state = spawn scheduled

	program identifier = teamid.my.agent.bundle.id  (mode: 1)
	parent bundle identifier = developer.id.bundle.id.instead.of.app.store.bundle.id

Resolution:

Once realizing that association was off... I looked at this file:

/var/db/com.apple.xpc.launchd/loginitems.userid.plist

It contains an association between login items and parent bundle IDs.

I manually edited the file to correct parent app bundle ID. Cleaned everything, rebooted, et voila!

Hope it helps.

Login Item failing to launch with SMAppService. Error: 78, LastExitStatus: 19968
 
 
Q