Permalink
Browse files

updates to ABPerson and ABAddressBook helper function

Added description to ABPerson
Added thumbnailImageData method to ABPerson
added firstName and lastName properties to ABPerson

added personWithRecordRef helper function to ABAddressBook
  • Loading branch information...
1 parent 33ad184 commit a63a0c9e3a61c509e249028cda820025d076fbb5 @tonymillion tonymillion committed Jun 26, 2011
Showing with 38 additions and 0 deletions.
  1. +1 −0 ABAddressBook.h
  2. +5 −0 ABAddressBook.m
  3. +4 −0 ABPerson.h
  4. +28 −0 ABPerson.m
View
@@ -78,6 +78,7 @@ enum
@property (nonatomic, readonly) NSUInteger personCount;
- (ABPerson *) personWithRecordID: (ABRecordID) recordID;
+- (ABPerson *) personWithRecordRef:(ABRecordRef) recordRef;
- (NSArray *) allPeople;
- (NSArray *) allPeopleSorted;
- (NSArray *) allPeopleWithName: (NSString *) name;
View
@@ -187,6 +187,11 @@ - (NSUInteger) personCount
return ( (NSUInteger) ABAddressBookGetPersonCount(_ref) );
}
+-(ABPerson *) personWithRecordRef:(ABRecordRef) recordRef
+{
+ return ( [[[ABPerson alloc] initWithABRef: recordRef] autorelease] );
+}
+
- (ABPerson *) personWithRecordID: (ABRecordID) recordID
{
ABRecordRef person = ABAddressBookGetPersonWithRecordID( _ref, recordID );
View
@@ -43,6 +43,8 @@
@interface ABPerson : ABRecord
// use -init to create a new person
+@property (readonly, getter = getFirstName) NSString * firstName;
+@property (readonly, getter = getLastName) NSString * lastName;
+ (ABPropertyType) typeOfProperty: (ABPropertyID) property;
+ (NSString *) localizedNameOfProperty: (ABPropertyID) property;
@@ -51,10 +53,12 @@
- (BOOL) setImageData: (NSData *) imageData error: (NSError **) error;
- (NSData *) imageData;
+- (NSData *) thumbnailImageData;
@property (nonatomic, readonly) BOOL hasImageData;
- (BOOL) removeImageData: (NSError **) error;
- (NSComparisonResult) compare: (ABPerson *) otherPerson;
- (NSComparisonResult) compare: (ABPerson *) otherPerson sortOrdering: (ABPersonSortOrdering) order;
+
@end
View
28 ABPerson.m 100644 → 100755
@@ -73,6 +73,11 @@ - (id) init
return ( [self initWithABRef: person] );
}
+- (NSString*) description
+{
+ return [NSString stringWithFormat: @"ABPerson %d - %@",[self recordID], [self compositeName]];
+}
+
- (BOOL) setImageData: (NSData *) imageData error: (NSError **) error
{
return ( (BOOL) ABPersonSetImageData(_ref, (CFDataRef)imageData, (CFErrorRef *)error) );
@@ -84,6 +89,12 @@ - (NSData *) imageData
return ( [imageData autorelease] );
}
+- (NSData *) thumbnailImageData
+{
+ NSData * imageData = (NSData *) ABPersonCopyImageDataWithFormat( _ref, kABPersonImageFormatThumbnail );
+ return ( [imageData autorelease] );
+}
+
- (BOOL) hasImageData
{
return ( (BOOL) ABPersonHasImageData(_ref) );
@@ -104,4 +115,21 @@ - (NSComparisonResult) compare: (ABPerson *) otherPerson sortOrdering: (ABPerson
return ( (NSComparisonResult) ABPersonComparePeopleByName(_ref, otherPerson->_ref, order) );
}
+-(NSString*)getFirstName
+{
+ return [self valueForProperty:kABPersonFirstNameProperty];
+}
+
+-(NSString*)getLastName
+{
+ NSString * lastName = [self valueForProperty:kABPersonLastNameProperty];
+
+ if(lastName == nil)
+ {
+ lastName = [self compositeName];
+ }
+
+ return lastName;
+}
+
@end

0 comments on commit a63a0c9

Please sign in to comment.