From 973315eb8e7a64c24db74f79a4a91887f9c455d6 Mon Sep 17 00:00:00 2001 From: Carlos Fonseca Date: Sat, 18 Jan 2014 19:58:15 +0000 Subject: [PATCH] Added optional fetch of thumbnail photo, which is the cropped version you create on the Address Book. --- Classes/APContact.h | 1 + Classes/APContact.m | 5 +++++ Classes/APTypes.h | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Classes/APContact.h b/Classes/APContact.h index 92ce8f7..0876e74 100644 --- a/Classes/APContact.h +++ b/Classes/APContact.h @@ -19,6 +19,7 @@ @property (nonatomic, readonly) NSArray *phones; @property (nonatomic, readonly) NSArray *emails; @property (nonatomic, readonly) UIImage *photo; +@property (nonatomic, readonly) UIImage *photoThumb; - (id)initWithRecordRef:(ABRecordRef)recordRef fieldMask:(APContactField)fieldMask; diff --git a/Classes/APContact.m b/Classes/APContact.m index e2c8b05..a2c9aa8 100644 --- a/Classes/APContact.m +++ b/Classes/APContact.m @@ -43,6 +43,11 @@ - (id)initWithRecordRef:(ABRecordRef)recordRef fieldMask:(APContactField)fieldMa NSData *imageData = (__bridge_transfer NSData *)ABPersonCopyImageData(recordRef); _photo = [UIImage imageWithData:imageData scale:UIScreen.mainScreen.scale]; } + if (fieldMask & APContactFieldPhotoThumb) + { + NSData *imageData = (__bridge_transfer NSData *)ABPersonCopyImageDataWithFormat(recordRef, kABPersonImageFormatThumbnail); + _photoThumb = [UIImage imageWithData:imageData scale:UIScreen.mainScreen.scale]; + } } return self; } diff --git a/Classes/APTypes.h b/Classes/APTypes.h index e71ddd2..904ced8 100644 --- a/Classes/APTypes.h +++ b/Classes/APTypes.h @@ -28,10 +28,11 @@ typedef enum APContactFieldPhones = 1 << 3, APContactFieldEmails = 1 << 4, APContactFieldPhoto = 1 << 5, + APContactFieldPhotoThumb= 1 << 6, APContactFieldDefault = APContactFieldFirstName | APContactFieldLastName | APContactFieldPhones, APContactFieldAll = APContactFieldDefault | APContactFieldCompany | - APContactFieldEmails | APContactFieldPhoto + APContactFieldEmails | APContactFieldPhoto | APContactFieldPhotoThumb } APContactField; #endif