Oh blah, I shoulda scrolled down )-: The above is my response to your first post. The following is in response to your subsequent ones.
I'm sorry I already tried to shorten it up - and failed :-D Thank you for reading through!
The former approach only works when you’re installing the agent yourself, because you control the entire launchd property list. Use the latter approach if you’re using SMAppService to install your agent.
I was actually using SMAppService.agent(plistName: )the whole time, I just took the information about the Bundle Identifier in AppSandboxLoginItemXPCDemo because I couldn't make the way with just the groups work. That was what I originally tried but never worked and I thought this is the way to do it. Or am I using this wrong? I'm copying the plist file with a build phase to Destination Wrapper into Contents/Library/LaunchAgents. This is the SMAppService way or do I have to do something different? Or is this mixed way between AppService and LoginItem?
instead of using a command line target I wrapped it in a App because I wasn't sure if AppGroups work on it. Should I just bundle that in a dummy bundle? Or is App the way to go?
Finally, there’s the question of IPC. One little known feature of app groups is that, by using an app group ID as a Mach service name prefix, you can communicate between sandboxed apps. In this case, the agent and app can both access the TTT.com.example.apple-samplecode.SandboxedAgent.group app group (where TTT is my Team ID), and thus the agent can register and listen on the TTT.com.example.apple-samplecode.SandboxedAgent.group.agent named XPC endpoint and the app can connect to it. Sneaky!
Hm, I wanted to do it this way but I think I did try different group/name syntax - and I now redid it again and its stilll failing - and it feels like at the same step.
I basically mixed what I learned from Signing a daemon with a restricted entitlement and Embedding a command-line tool in a sandboxed app
I will summarise what I did, maybe you can sport something because this really feels like something simple. I'm not sure if I'm doing the right thing with the group names and the XCP endpoint - but before that - my process is never there.
Main.app
BundleIdentifier: com.myapp
AppGroup: XXX.com.myapp.group
Helper.app
Its an .app Target
BundleIdentifier: com.myapp.helper
Entitlements: just Sandbox and Hardened Runtime
AppGroup: XXX.com.myapp.group
disabled CODE_SIGN_INJECT_BASE_ENTITLEMENTS
enabled CREATE_INFOPLIST_SECTION_IN_BINARY
Gets embedded to Destination: Executables
I checked for my application-identifier in the entitlements like described in Signing a daemon with a restricted entitlement and it was missing it. I added Custom Network Protocol Capability to Entitlements just to get an automatic provisioning profile that's embedded in the Helper.app and test if that is the problem. But it doesn't matter, with or without it doesn't change.
com.myapp.Helper.plist
Label: com.myapp.Helper
BundleProgram: Contents/MacOS/Helper.app
MachServices: XXXX.myapp.Helper true <-- do I actually need this?
Gets copied to to Destination: Wrappers - Contents/Library/LaunchAgents
listening XPC Connection
XXX.com.myapp.group.Helper
This is different. I tried listening on just the group or the helper bundle Identifier but not a mix of .group.Name. I dont think you did a typo there. But I cant try it it really because of the problems below
But my XPC Connection always fails the same way
failed at lookup with error 3 - No such process
And I believe it - there never is such process, but why? I think my problem lies on getting the launch agent started correctly or there is no such process because its a sandboxing situation?
After registering the LaunchAgent in my App with SMAppService.agent(plistName: ) this is happening in console:
effectiveDisposition: getRelationship failed, url=file:///Users/user/Library/Developer/Xcode/DerivedData/myapp-hdapfcmolqdbcfeymucseidhmqzh/Build/Products/Debug/myapp/Contents/Library/LaunchAgents/com.myapp.Helper.plist, error: Error Domain=NSCocoaErrorDomain Code=3328 "The requested operation couldn’t be completed because the feature is not supported." UserInfo={NSUnderlyingError=0x7f9535a0f5f0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
No such file - It looks like it cant launch because the executable is not there. But Helper.app is in Contents/MacOS and the plist is in LaucnhAgents
effectiveDisposition: getRelationship failed, item=uuid=5E6A0905-4B0C-4EA7-B09A-47F0DC6F69D6, name=Helper.app, type=agent, disposition=[enabled, allowed, visible, notified], identifier=com.myapp.Helper, url=Contents/Library/LaunchAgents/com.myapp.Helper.plist -- file:///
this one looks almost cut off - there is nothing after file:///
copyJobWithLabel for label com.myapp.Helper failed with error 113: Could not find specified service
itemWithAppURL: appURL=file:///Users/user/Library/Developer/Xcode/DerivedData/myapp-hdapfcmolqdbcfeymucseidhmqzh/Build/Products/Debug/myapp.app/, type=agent, url=Contents/Library/LaunchAgents/com.myapp.Helper.plist -- file:///, config={
BTMConfigArguments = (
);
BTMConfigBundleIdentifiers = (
);
BTMConfigExecutablePath = "Contents/MacOS/Helper.app";
BTMConfigLabel = "com.myapp.Helper";
BTMConfigSHA256Checksum = {length = 32, bytes = 0xcf54e082 1fda0f68 9988aa21 227bd4d7 ... 51f3d096 7aefaabc };
} uid=501
I have moved around everything I could think of but it's just not happy. I'm guessing I'm doing some obvious thing wrong but it all looks like its at the right place
The problèm seems to start at my LaunchAgent isn't starting but I have no idea why.
Thank you!
Benjamin