diff -r 1d6924779df7 -r 60f2b46d9a3b Bonjour/MYBonjourBrowser.m --- a/Bonjour/MYBonjourBrowser.m Wed Apr 29 13:29:31 2009 -0700 +++ b/Bonjour/MYBonjourBrowser.m Sat May 16 14:10:15 2009 -0700 @@ -200,6 +200,7 @@ + #pragma mark - #pragma mark TESTING: @@ -221,8 +222,12 @@ self = [super init]; if (self != nil) { _browser = [[MYBonjourBrowser alloc] initWithServiceType: @"_presence._tcp"]; - [_browser addObserver: self forKeyPath: @"services" options: NSKeyValueObservingOptionNew context: NULL]; - [_browser addObserver: self forKeyPath: @"browsing" options: NSKeyValueObservingOptionNew context: NULL]; + [_browser addObserver: self forKeyPath: @"services" + options: NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew + context: NULL]; + [_browser addObserver: self forKeyPath: @"browsing" + options: NSKeyValueObservingOptionNew + context: NULL]; [_browser start]; MYBonjourRegistration *myReg = _browser.myRegistration; @@ -243,7 +248,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - LogTo(Bonjour,@"Observed change in %@: %@",keyPath,change); + Log(@"Observed change in %@: %@",keyPath,change); if( $equal(keyPath,@"services") ) { if( [[change objectForKey: NSKeyValueChangeKindKey] intValue]==NSKeyValueChangeInsertion ) { NSSet *newServices = [change objectForKey: NSKeyValueChangeNewKey]; @@ -252,8 +257,18 @@ Log(@"##### %@ : at %@:%hu, TXT=%@", service, hostname, service.port, service.txtRecord); service.addressLookup.continuous = YES; + [service.addressLookup addObserver: self + forKeyPath: @"addresses" + options: NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew + context: NULL]; [service queryForRecord: kDNSServiceType_NULL]; } + } else if( [[change objectForKey: NSKeyValueChangeKindKey] intValue]==NSKeyValueChangeRemoval ) { + NSSet *oldServices = [change objectForKey: NSKeyValueChangeOldKey]; + for( MYBonjourService *service in oldServices ) { + Log(@"##### REMOVED: %@", service); + [service.addressLookup removeObserver: self forKeyPath: @"addresses"]; + } } } }