Hi,
the LaunchAgent is implemented with this (cutout):
@interface ServiceDelegate : NSObject
@end
@implementation ServiceDelegate
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(pEpMacOSAdapterProtocol)];
pEpMacOSAdapter *exportedObject = [pEpMacOSAdapter new];
newConnection.exportedObject = exportedObject;
[newConnection resume];
return YES;
}
@end
int main(int argc, const char *argv[])
{
ServiceDelegate *delegate = [ServiceDelegate new];
NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName:@"foundation.pEp.adapter.macOS"];
[listener resume];
[[NSRunLoop currentRunLoop] run];
return 0;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict> <key>Label</key>
<string>foundation.pEp.adapter.macOS</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/pEp/foundation.pEp.adapter.macOS</string>
</array>
<key>MachServices</key>
<dict>
<key>foundation.pEp.adapter.macOS</key>
<true/>
</dict>
</dict>
</plist>
The App is implemented with this (cutout):
func proxyErrorHandler(err: Error) -> Void {
NSLog("%@", err.localizedDescription)
statusText.title = NSLocalizedString("Connection failed", comment: "")
}
internal func applicationDidFinishLaunching(_ aNotification: Notification) {
connection = NSXPCConnection.init(machServiceName: "foundation.pEp.adapter.macOS")
if connection != nil {
connection.remoteObjectInterface = NSXPCInterface.init(with: pEpMacOSAdapterProtocol.self)
connection.resume()
statusText.title = NSLocalizedString("Connecting…", comment: "")
proxy = connection.remoteObjectProxyWithErrorHandler(proxyErrorHandler) as? pEpMacOSAdapterProtocol
proxy?.subscribeForUpdate(downloadNotification: notifyDownload)
}
else {
NSLog("pEpNotifications: %@", "cannot connect to pEp.foundation.adapter.macOS")
}
}
I'm always getting proxyErrorHandler() called with "Couldn’t communicate with a helper application."
Any ideas?
it's the right thing to do.
Cool. In that case you need to punch a whole through your sandbox so that your app can connect to the XPC service being advertised by your agent. You can do this using the global Mach service temporary exception (
com.apple.security.temporary-exception.mach-lookup.global-name
).
Outgoing Connections (Client) is checkmarked.
That is only relevant for networking connections, not for XPC.
I'm unsure if this can fit into App Store what we're doing.
A
launchd
agent is definitely incompatible with the Mac App Store. However, Mac App Store apps can run code at login using an ServiceManager login item. You can even arrange for these to advertise an XPC service that your app can use to communicate with it. See
SMLoginItemSetEnabled
and
AppSandboxLoginItemXPCDemo.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"