- (NSString *) findNameOfContactInAddressBook:(NSString *)phoneNumber {
NSString *lastFourDigits = [phoneNumber substringFromIndex:[phoneNumber length] - 4];
ABAddressBook *AB = [ABAddressBook sharedAddressBook];
ABSearchElement *pn = [ABPerson searchElementForProperty:kABPhoneProperty
label:nil
key:nil
value:lastFourDigits
comparison:kABSuffixMatchCaseInsensitive];
NSArray *peopleFound = [AB recordsMatchingSearchElement:pn];
if ([peopleFound count] > 0) {
for (int i = 0; i < [peopleFound count]; i++) {
ABPerson *person = [peopleFound objectAtIndex:0];
ABMultiValue *phones = [person valueForProperty:kABPhoneProperty];
for (int j = 0; j < [phones count]; j++) {
if ([[self normalizePhoneNumber:[phones valueAtIndex:j]] isEqualToString:phoneNumber]) {
return [NSString stringWithFormat:@"%@ %@", [person valueForProperty:kABFirstNameProperty], [person valueForProperty:kABLastNameProperty]];
}
}
}
}
return phoneNumber;
}