Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helper mac app (Login Item), unable to communicate with

I've done exactly as the Sandboxed Helper App example provided by Apple and all seems to be running fine. I'm able to successfully create a NSXPCConnection object and also get back my remote object (via remoteObjectProxyWithErrorHandler).

However when I call a method on the proxy object (defined in the Protocol definition), I get back this error:

Failed to connect to launch agent: Error Domain=NSCocoaErrorDomain Code=4099 "Couldn’t communicate with a helper application.

Essentially no matter what I do I'm not able to communicate with my helper app. I'm doing nothing fancy, just trying to make a simple call to the helper app to NSLog() something. But it doesn't work. Strangely I also don't see any output from inside:

- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection

What could I possibly be doing wrong?

UPDATE: Apparently if I uncheck 'Enable App Sandboxing' on my main app, it works! So there's something wrong with enabling sandboxing after which it does not want to communicate with my helper app. Do I need more entitlements? I've tried them all under xcode!

like image 421
strange Avatar asked Sep 01 '12 13:09

strange


People also ask

What is the helper app on Mac?

Helper Helper is a community service app that connects volunteers to meaningful experiences in the community.

How do I get rid of open login apps on Mac?

Remove a login item: Select the name of the item you want to prevent from opening automatically, then click the Remove button below the list. Hide a login item: If you don't want an item's windows to be visible after login, select the Hide checkbox next to the item.

How do I fix an unresponsive app on my Mac?

Choose Apple menu > Force Quit, select the app in the dialog that appears, then click Force Quit. If the app quit, reopen it by clicking Reopen in the dialog that appears. Restart your Mac by choosing Apple menu > Restart. Make sure the app is compatible with your version of macOS.

Why is my Mac saying this application Cannot be opened?

You may not have the privileges to open the app, the app may be damaged, or it may not be installed. If you aren't an administrator of your Mac, the administrator may be preventing you from using the app. Contact the administrator of your Mac.


2 Answers

Your helper application is sandboxed. Therefore, it cannot register a mach service dynamically, although Xcode allows it for debug purpose.

However, when you add your helper application to login items (using SMLoginItemSetEnabled() ), launchd will automatically register a mach service for you named with its bundle identifier.

Now your main application is sandboxed. Therefore, random mach communication is not allowed. The only way to make it work was to add a temporary mach lookup entitlement.

Since 10.7.4. Apple introduced the application-groups entitlements as a solution for this case, where an application needs to communicate with a helper app.

Both applications have to share the same application-groups entitlement. It can be any value, but Apple requires that this value must start with your Team-ID (e.g: Team-id.myApp). Then, your helper application bundle identifier must start with that same entitlement (e.g Team-id.myApp.myHelperApp). After that, your main application can freely communicate with your helper application using a XPC communication with the service named with the helper application bundle identifier (i.e. Team-id.myApp.myHelperApp). Also, the two applications will share access to a group container folder named with the application group entitlement (e.g. ~/Library/Group Containers/Team-id.myApp), that you have to create manually if you will need it.

like image 124
Samir Avatar answered Oct 17 '22 05:10

Samir


Okay so I've learned the hard way - there are tons of issues with Sandboxing and XPC not to mention helper apps and sharing databases using the so called 'shared group directory' which neither gets created automatically (as the documentation incorrectly says) nor does NSURL offer the method it claims to in the documentation.

Although the documentation says that in the Entitlements you can specify any string as the 'shared app identifier' in the format <TEAM_ID>.whatever, apparently it will ONLY work if you use the format: <TEAM_ID>.com.yourcompany

Anything else and it won't work. It'll compile, it'll archive, it'll run but it won't let you talk to your helper app. After spending around 30 hours I thought heck I'll try that one last change and apparently that was it! Filing a radar on the horribly written sandboxing documentation (which a lot on Apple's Developer forum are complaining about) next...

like image 4
strange Avatar answered Oct 17 '22 06:10

strange