NSConnection在10.8之后死了一段时间

时间:2013-01-25 08:39:27

标签: macos cocoa distributed-objects nsconnection

我正在使用DO for IPC。我使用以下代码。它的工作正常在10.6和10.7但在10.8甚至两种应用都是理想的。

// HELPER

NSConnection *connection =[NSConnection new];
[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(connectionDidDie:)
                                                  name:NSConnectionDidDieNotification
                                                   object:nil];
[connection setRootObject:syncManager];  
if ([connection registerName:SYNC_SERVER_NAME] == NO){
       NSLog(@"Error registering server");
} 
- (void)connectionDidDie:(NSNotification *)aNotification{ 
     NSConnection     *deadConnection = [aNotification object];
     id    currentClient = [self.clientsList objectAtIndex:0];
     NS_DURING
     if([currentClient respondsToSelector:@selector(connectionForProxy)]) {
          if(deadConnection == [currentClient connectionForProxy]){
                 // remove proxy with dead connection
                 [clientsList removeObjectAtIndex:0];
                 NSLog(@"Removed client from client list.");
           }
     }
     NS_HANDLER
     [self.clientsList removeObjectAtIndex:0];
     NS_ENDHANDLER

}

// UI App

// ------
self.server = [NSConnection rootProxyForConnectionWithRegisteredName:SYNC_SERVER_NAME host:nil];
if(nil != self.server){
[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(connectionDidDie:)
                                                     name:NSConnectionDidDieNotification
                                                   object:nil];
[self.server addMessageClient:self];
[self.server setProtocolForProxy:@protocol(MDMessageProtocol)];
//------

- (void)connectionDidDie:(NSNotification *)aNotification{
    NSLog(@"Error: Connection to server is broken");
}

0 个答案:

没有答案