5

我将 DO 与 IPC 一起使用。我使用了以下代码。它在 10.6 和 10.7 中工作正常,但在 10.8 模具上,即使这两种应用程序都是理想的。

// 助手

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

}

// 用户界面应用

// ------
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");
}
4

0 回答 0