diff --git a/Classes/APContact.h b/Classes/APContact.h index dd9bf99..52eb3ff 100644 --- a/Classes/APContact.h +++ b/Classes/APContact.h @@ -24,6 +24,8 @@ @property (nonatomic, readonly) UIImage *photo; @property (nonatomic, readonly) UIImage *thumbnail; @property (nonatomic, readonly) NSNumber *recordID; +@property (nonatomic, readonly) NSDate *creationDate; +@property (nonatomic, readonly) NSDate *modificationDate; - (id)initWithRecordRef:(ABRecordRef)recordRef fieldMask:(APContactField)fieldMask; diff --git a/Classes/APContact.m b/Classes/APContact.m index 8aea516..17a3460 100644 --- a/Classes/APContact.m +++ b/Classes/APContact.m @@ -71,6 +71,12 @@ - (id)initWithRecordRef:(ABRecordRef)recordRef fieldMask:(APContactField)fieldMa { _recordID = [NSNumber numberWithInteger:ABRecordGetRecordID(recordRef)]; } + if (fieldMask & APContactFieldCreationDate) { + _creationDate = [self dateProperty:kABPersonCreationDateProperty fromRecord:recordRef]; + } + if (fieldMask & APContactFieldModificationDate) { + _modificationDate = [self dateProperty:kABPersonModificationDateProperty fromRecord:recordRef]; + } } return self; } @@ -99,6 +105,13 @@ - (NSArray *)arrayProperty:(ABPropertyID)property fromRecord:(ABRecordRef)record return array.copy; } + +- (NSDate *)dateProperty:(ABPropertyID)property fromRecord:(ABRecordRef)recordRef +{ + CFDateRef dateRef = (ABRecordCopyValue(recordRef, property)); + return (__bridge_transfer NSDate *)dateRef; +} + - (NSArray *)arrayOfPhonesWithLabelsFromRecord:(ABRecordRef)recordRef { NSMutableArray *array = [[NSMutableArray alloc] init]; diff --git a/Classes/APTypes.h b/Classes/APTypes.h index 5c3f6ba..e88dcf8 100644 --- a/Classes/APTypes.h +++ b/Classes/APTypes.h @@ -33,6 +33,8 @@ typedef NS_OPTIONS(NSUInteger , APContactField) APContactFieldCompositeName = 1 << 8, APContactFieldAddresses = 1 << 9, APContactFieldRecordID = 1 << 10, + APContactFieldCreationDate = 1 << 11, + APContactFieldModificationDate = 1 << 12, APContactFieldDefault = APContactFieldFirstName | APContactFieldLastName | APContactFieldPhones, APContactFieldAll = 0xFFFF diff --git a/README.md b/README.md index 4fa57f8..e6c66b8 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ APAddressBook is a wrapper on [AddressBook.framework](https://developer.apple.co #### Installation Add `APAddressBook` pod to Podfile +```ruby +platform :ios, '7.0' +pod "APAddressBook", "~> 0.0.7" +``` #### Using @@ -38,11 +42,13 @@ APAddressBook *addressBook = [[APAddressBook alloc] init]; Available fields: * APContactFieldFirstName - *contact first name* * APContactFieldLastName - *contact last name* -* APContactFieldCompany - *contact company (organisation)* +* APContactFieldCompany - *contact company (organization)* * APContactFieldPhones - *contact phones array* * APContactFieldEmails - *contact emails array* * APContactFieldPhoto - *contact photo* * APContactFieldThumbnail - *contact thumbnail* +* APContactFieldCreationDate - *contact creation date* +* APContactFieldModificationDate - *contact modification date* * APContactFieldPhonesWithLabels - *contact phones with labels* * APContactFieldCompositeName - *the concatenated value of prefix, suffix, organization, first name, and last name* * APContactFieldAddresses - *array of user addresses*