1

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

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

- (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。

4

2 回答 2

1

NSConnection保持对Ken Thomases 提出的对象的强烈引用会有所帮助。

于 2013-03-15T13:28:30.317 回答
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
于 2013-03-14T06:39:43.903 回答