我有两个 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。