5

IPC に DO を使用しています。次のコードを使用しました。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

}

// UI アプリ

// ------
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