May 13, 2009
Recently, Apple released an update to Mac OS X that broke syncing in my app ShoveBox. The app syncs over the user's local WiFi network and uses Bonjour in order to find the iPhone/iPod version of ShoveBox.
A few fellow developers were curious what was changed in 10.5.7, so I thought I'd post it here.
After some troubleshooting, I found that Apple had made a slight tweak to the way the Cocoa APIs for Bonjour work. As of 10.5.6 and below, if you called
-startMonitoring on an NSNetService, it would immediately call the delegate method
– netService:didUpdateTXTRecordData: to let you know that the TXT record changed or became available, even if it had not changed from when
-startMonitoring was called.
I'm not sure what I was under the influence of when writing this part of ShoveBox, but I had (perhaps defensively) coded it to only count the NSNetService as a viable sync source once
–netService:didUpdateTXTRecordData: was called — as it did seem to be called in every case.
As of 10.5.7, NSNetService (correctly) only calls that method once the TXT record has actually changed.
The fix involved checking for/validating the TXT record for the NSNetService as soon as its address is resolved (in
– netServiceDidResolveAddress:). Now, only if it is not present and valid, it I call
-startMonitoring. It should be sufficient, however, to only validate once if the broadcasting application does not change its TXT records.
© 2013 Dan Grover. All rights reserved.