سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top