Question

I have two Cocoa-GUI-Applications (compiled with ARC, no sandboxing).

Application one has the following function:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application

    CommController *cc = [CommController new];
    NSConnection *theConnection;
    theConnection = [NSConnection new];
    [theConnection setRootObject:cc];
    if ([theConnection registerName:@"MyServer"] == NO) {
        /* Handle error. */
        NSLog(@"Could not start server.");
    }

}

And application two has the following function:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    id theProxy;
    NSConnection *theConnection;

    theConnection = [NSConnection
                     connectionWithRegisteredName:@"MyServer"
                     host:nil];
    theProxy = [theConnection rootProxy];
    [theProxy setProtocolForProxy:@protocol(NetProto)];

}

The call [theConnection rootProxy] from the second application never returns. If I use the deprecated [NSConnection defaultConnection] instead of [NSConnection new] it works. So I'm looking for a non deprecated way to get the rootProxy.

Was it helpful?

Solution

Keeping a strong reference to the NSConnection object as proposed by Ken Thomases helped.

OTHER TIPS

CommController *cc = [CommController new];
    NSConnection *theConnection;
    theConnection = [NSConnection new];
    [theConnection setRootObject:cc];
    if ([theConnection registerName:@"MyServer"] == NO) {
        /* Handle error. */
        NSLog(@"Could not start server.");
    }
[[NSRunLoop currentRunLoop] run];//Start the current runloop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top