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