Skip to content

Implemented peopleWithPhone in RHAddressBook #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RHAddressBook/RHAddressBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ typedef NS_ENUM(NSUInteger, RHAuthorizationStatus) {

-(NSArray*)peopleWithName:(NSString*)name;
-(NSArray*)peopleWithEmail:(NSString*)email;
-(NSArray*)peopleWithPhone:(NSString*)phone;

-(RHPerson*)personForABRecordRef:(ABRecordRef)personRef; //returns nil if ref not found in the current ab, eg unsaved record from another ab. if the passed recordRef does not belong to the current addressbook, the returned person objects underlying personRef will differ from the passed in value. This is required in-order to maintain thread safety for the underlying AddressBook instance.
-(RHPerson*)personForABRecordID:(ABRecordID)personID; //returns nil if not found in the current ab, eg unsaved record from another ab.

Expand Down
15 changes: 15 additions & 0 deletions RHAddressBook/RHAddressBook.m
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,21 @@ -(NSArray*)peopleWithEmail:(NSString*)email{
return [NSArray arrayWithArray:result];
}

-(NSArray*)peopleWithPhone:(NSString*)phone{

NSMutableArray *result = [NSMutableArray array];
rh_dispatch_sync_for_addressbook(self, ^{
for(RHPerson *person in [self people]) {
NSArray *phones = [[person.phoneNumbers values] valueForKey:@"lowercaseString"];
if ([phones containsObject:phone]){
[result addObject:person];
}
}
});

return [NSArray arrayWithArray:result];
}

-(RHPerson*)personForABRecordRef:(ABRecordRef)personRef{

if (personRef == NULL) return nil; //bail
Expand Down