Skip to content

Commit

Permalink
Merge pull request #8 from NatashaTheRobot/add_created_modified_conta…
Browse files Browse the repository at this point in the history
…ct_fields

Add created modified contact fields
  • Loading branch information
belkevich committed May 21, 2014
2 parents f28d993 + 61d90a4 commit 5ccba8d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Classes/APContact.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions Classes/APContact.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions Classes/APTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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*
Expand Down

0 comments on commit 5ccba8d

Please sign in to comment.