Re: TXT Records with NSImages
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