From fa3512da90df8b2dedc5ceb1cf302d603876c286 Mon Sep 17 00:00:00 2001 From: Kostas Antonopoulos Date: Fri, 27 Feb 2015 00:36:42 +0200 Subject: [PATCH] Implemented peopleWithPhone in RHAddressBook --- RHAddressBook/RHAddressBook.h | 2 ++ RHAddressBook/RHAddressBook.m | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/RHAddressBook/RHAddressBook.h b/RHAddressBook/RHAddressBook.h index c5e9d59..29e0018 100644 --- a/RHAddressBook/RHAddressBook.h +++ b/RHAddressBook/RHAddressBook.h @@ -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. diff --git a/RHAddressBook/RHAddressBook.m b/RHAddressBook/RHAddressBook.m index 95aaa03..71aa24d 100644 --- a/RHAddressBook/RHAddressBook.m +++ b/RHAddressBook/RHAddressBook.m @@ -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