在NSConnections上调用rootProxy不会返回

时间:2013-03-13 16:12:32

标签: objective-c xcode cocoa distributed-objects

我有两个Cocoa-GUI-Applications(使用ARC编译,没有沙盒)。

应用程序1具有以下功能:

- (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.");
    }

}

应用程序二具有以下功能:

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

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

}

来自第二个应用程序的调用[theConnection rootProxy]永远不会返回。 如果我使用弃用的[NSConnection defaultConnection]而不是[NSConnection new],则可以使用。 所以我正在寻找一种非弃用的方法来获取rootProxy。

2 个答案:

答案 0 :(得分:1)

对Ken Thomases提出的NSConnection对象进行强有力的参考帮助。

答案 1 :(得分:0)

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