Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

minor additions to ABAddressBook and to ABPerson #3

Merged
merged 6 commits into from

3 participants

Tony Million Jim Dovey David Beck
Tony Million

Merged Notifications from davbeck

Added thumbnailImageData , firstName and lastName methods to ABPerson

Added personWithRecordRef helper function to ABAddressbook

tonymillion and others added some commits
Tony Million tonymillion 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
a63a0c9
David Beck davbeck Added AddressBook did change notification a0acd99
David Beck davbeck Added notification for when the address book is saved f2be904
David Beck davbeck Added loading HUD c4767dc
Tony Million tonymillion Revert "Added loading HUD"
This reverts commit c4767dca279227653b2da5a8b74e3237c39e757a.
4d19539
Tony Million tonymillion protected delegate against existence and making sure it actually resp…
…onds!
fdf249e
Jim Dovey AlanQuatermain merged commit ab6e963 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 26, 2011
  1. Tony Million

    updates to ABPerson and ABAddressBook helper function

    tonymillion authored
    Added description to ABPerson
    Added thumbnailImageData method to ABPerson
    added firstName and lastName properties to ABPerson
    
    added personWithRecordRef helper function to ABAddressBook
  2. David Beck Tony Million

    Added AddressBook did change notification

    davbeck authored tonymillion committed
  3. David Beck Tony Million

    Added notification for when the address book is saved

    davbeck authored tonymillion committed
  4. David Beck Tony Million

    Added loading HUD

    davbeck authored tonymillion committed
  5. Tony Million

    Revert "Added loading HUD"

    tonymillion authored
    This reverts commit c4767dca279227653b2da5a8b74e3237c39e757a.
  6. Tony Million
This page is out of date. Refresh to see the latest.
Showing with 55 additions and 15 deletions.
  1. +3 −0  ABAddressBook.h
  2. +20 −15 ABAddressBook.m
  3. +4 −0 ABPerson.h
  4. +28 −0 ABPerson.m
3  ABAddressBook.h
View
@@ -43,6 +43,8 @@
@class ABRecord, ABPerson, ABGroup, ABSource;
@protocol ABAddressBookDelegate;
+extern NSString *ABAddressBookDidChangeNotification;
+
enum
{
ABOperationNotPermittedByStoreError = kABOperationNotPermittedByStoreError
@@ -78,6 +80,7 @@ enum
@property (nonatomic, readonly) NSUInteger personCount;
- (ABPerson *) personWithRecordID: (ABRecordID) recordID;
+- (ABPerson *) personWithRecordRef:(ABRecordRef) recordRef;
- (NSArray *) allPeople;
- (NSArray *) allPeopleSorted;
- (NSArray *) allPeopleWithName: (NSString *) name;
35 ABAddressBook.m
View
@@ -43,6 +43,8 @@
#import "ABGroup.h"
#import "ABSource.h"
+NSString *ABAddressBookDidChangeNotification = @"ABAddressBookDidChange";
+
NSArray * WrappedArrayOfRecords( NSArray * records, Class<ABRefInitialization> wrapperClass )
{
NSMutableArray * wrapped = [[NSMutableArray alloc] initWithCapacity: [records count]];
@@ -100,21 +102,19 @@ - (id) initWithABRef: (CFTypeRef) ref
// we can't to CFTypeID checking on AB types, so we have to trust the user
_ref = (ABAddressBookRef) CFRetain(ref);
+
+ ABAddressBookRegisterExternalChangeCallback( _ref, _ExternalChangeCallback, self );
return ( self );
}
- (id) init
{
- if ( [super init] == nil )
- return ( nil );
+ ABAddressBookRef ref = ABAddressBookCreate();
- _ref = ABAddressBookCreate();
- if ( _ref == NULL )
- {
- [self release];
- return ( nil );
- }
+ self = [self initWithABRef:ref];
+
+ CFRelease(ref);
return ( self );
}
@@ -134,17 +134,14 @@ - (void) dealloc
- (void) setDelegate: (id<ABAddressBookDelegate>) delegate
{
- if ( (_delegate == nil) && (delegate != nil) )
- ABAddressBookRegisterExternalChangeCallback( _ref, _ExternalChangeCallback, self );
- else if ( (_delegate != nil) && (delegate == nil) )
- ABAddressBookUnregisterExternalChangeCallback( _ref, _ExternalChangeCallback, self );
-
_delegate = delegate;
}
- (BOOL) save: (NSError **) error
{
- return ( (BOOL) ABAddressBookSave(_ref, (CFErrorRef *)error) );
+ BOOL result = (BOOL) ABAddressBookSave(_ref, (CFErrorRef *)error);
+ [[NSNotificationCenter defaultCenter] postNotificationName:ABAddressBookDidChangeNotification object:self];
+ return ( result );
}
- (BOOL) hasUnsavedChanges
@@ -175,7 +172,10 @@ - (void) revert
- (void) _handleExternalChangeCallback
{
- [_delegate addressBookDidChange: self];
+ if(_delegate && [_delegate respondsToSelector:@selector(addressBookDidChange:)])
+ [_delegate addressBookDidChange: self];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:ABAddressBookDidChangeNotification object:self];
}
@end
@@ -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 );
4 ABPerson.h
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
28 ABPerson.m 100644 → 100755
View
@@ -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
Something went wrong with that request. Please try again.