Bonjour/MYBonjourRegistration.m
changeset 53 e9f209a24d53
parent 31 1d6924779df7
child 50 63baa74c903f
     1.1 --- a/Bonjour/MYBonjourRegistration.m	Wed Apr 29 13:29:31 2009 -0700
     1.2 +++ b/Bonjour/MYBonjourRegistration.m	Tue Jun 23 12:46:40 2009 -0700
     1.3 @@ -148,10 +148,24 @@
     1.4  }
     1.5  
     1.6  
     1.7 ++ (NSData*) dataFromTXTRecordDictionary: (NSDictionary*)txtDict {
     1.8 +    // First translate any non-NSData values into UTF-8 formatted description data:
     1.9 +    NSMutableDictionary *encodedDict = $mdict();
    1.10 +    for (NSString *key in txtDict) {
    1.11 +        id value = [txtDict objectForKey: key];
    1.12 +        if (![value isKindOfClass: [NSData class]]) {
    1.13 +            value = [[value description] dataUsingEncoding: NSUTF8StringEncoding];
    1.14 +        }
    1.15 +        [encodedDict setObject: value forKey: key];
    1.16 +    }
    1.17 +    return [NSNetService dataFromTXTRecordDictionary: encodedDict];
    1.18 +}
    1.19 +
    1.20 +
    1.21  - (void) updateTxtRecord {
    1.22      [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(updateTxtRecord) object: nil];
    1.23      if (self.serviceRef) {
    1.24 -        NSData *data = [NSNetService dataFromTXTRecordDictionary: _txtRecord];
    1.25 +        NSData *data = [[self class] dataFromTXTRecordDictionary: _txtRecord];
    1.26          Assert(data!=nil, @"Can't convert dictionary to TXT record");
    1.27          DNSServiceErrorType err = DNSServiceUpdateRecord(self.serviceRef,
    1.28                                                           NULL,