• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: TXT Records with NSImages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TXT Records with NSImages


  • Subject: Re: TXT Records with NSImages
  • From: Keith Duncan <email@hidden>
  • Date: Sat, 14 Mar 2009 00:35:28 +0000

Joe,

You'll need to drop below NSNetService and CFNetService to manipulate the NULL record data. Take a look at the API in dns_sd.h for the functions you need. Like a TXT record, a NULL record has a limit of 65535 bytes but unlike the TXT record it isn't segmented.

Here's some sample code (from an iPhone application) to get you started:

if (ABPersonHasImageData(self.personRecord)) {
NSData *rawAvatarData = (id)ABPersonCopyImageData(self.personRecord);

UIImage *avatarImage = [UIImage imageWithData:rawAvatarData];
NSData *avatarData = UIImageJPEGRepresentation(avatarImage, 0);

unsigned char hash[CC_SHA1_DIGEST_LENGTH];
CC_SHA1([avatarData bytes], [avatarData length], hash);

NSMutableString *hashString = [NSMutableString stringWithCapacity: (CC_SHA1_DIGEST_LENGTH * 2)];

for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
[hashString appendFormat:@"x", (unsigned long)hash[i], nil];

[self.TXTProperties setObject:hashString forKey:@"phsh"];

if (avatarRecord == NULL) {
error = DNSServiceAddRecord(_service, &avatarRecord, 0, kDNSServiceType_NULL, [avatarData length], [avatarData bytes], 0);
} else {
error = DNSServiceUpdateRecord(_service, avatarRecord, 0, [avatarData length], [avatarData bytes], 0);
}
} else {
error = DNSServiceRemoveRecord(_service, avatarRecord, 0);
avatarRecord = NULL;

[self.TXTProperties removeObjectForKey:@"phsh"];
}


Keith
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >TXT Records with NSImages (From: Joe Turner <email@hidden>)
 >Re: TXT Records with NSImages (From: Keith Duncan <email@hidden>)
 >Re: TXT Records with NSImages (From: Joe Turner <email@hidden>)

  • Prev by Date: Re: Performance problem with GC enabled
  • Next by Date: Re: Performance problem with GC enabled
  • Previous by thread: Re: TXT Records with NSImages
  • Next by thread: Getting the front process path
  • Index(es):
    • Date
    • Thread