简体   繁体   中英

NSConnection between an OSX app and a command line tool

I am trying to create a connection between an OSX app and a command line tool to work with distributed objects.

The connection is registered in the command line tool like this

[NSConnection serviceConnectionWithName:@"server" rootObject:extManager];

and an attempt to connect to the registered connection object is made from the app like this

self.serverConnection = [NSConnection connectionWithRegisteredName:@"server" host:nil];

When the app is NOT sandboxed the connection is made. When the app is sandboxed the connectionWithRegisteredName returns nil.

I have tried adding a key and value to the entitlements and signing both the tool and the app with the team certificate but it doesn't work

    <key>com.apple.security.application-groups</key>
    <array>
        <string><TEAM ID>.AppSuite</string>
    </array>

What can I do to make the connection work when sandboxed?

The trick here is to use the app-group name as a prefix in the connection name. ie:

self.serverConnection = [NSConnection connectionWithRegisteredName:@"<TEAM ID>.AppSuite.server" host:nil];

Why?

Mach port names must begin with the application group identifier, followed by a period (.), followed by a name of your choosing.
For example, if your application group's name is Z123456789.com.example.app-group, [...] You might create a Mach port named Z123456789.com.example.app-group.Port_of_Kobe.
Ref

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM