How to find an address book with a phone number?

I just want to search my IPhone address book by the number of the received phone call. How can I continue further in this case? Suppose my received call is in the format (ISD code) xxxxxxxxxx, for example (+1 1234567890) or (001 1234567890) or (+11234567890) or (+1 (123) 456-7890) or (1234567890 without ISD code) or something different. So, how can I find the entire address book database to get contact information using only (ISD CODE) 1234567890? Can someone help me?

Regards, Prathap.

+4
source share
4 answers

While browsing the Internet and browsing through the API, I came across them: "SHOULD NO WAY TO DO IT." Phone numbers are stored in the address book (if you add a phone number via "contacts", ph num will be saved in a different format if the phone number is copied from a SIM card and then saved in a different format) in a formatted format based on localization settings. In order to get a contact with a phone number, the phone number must be formatted in accordance with the localization settings and the entire address book should be viewed.

+1
source

Here is an interesting thing that I learned about how Android handles the caller ID (how to quickly and easily get a name for an incoming call)

Instead of storing the extension numbers in the address book database as +1 (555) 666-1234, store them in the reverse order, for example 43216665551. Thus, when the call comes in, the incoming phone number (43216665551) is in the opposite direction, take only the first 10 digits (4321666555), and your SQL looks something like this: "WHERE phone_number LIKE" 4321666555% "

This does not answer your question, but someone may find this useful.

+4
source

You can remove all spaces and brackets and compare only numbers with the longest suffix match.

And searching the entire address book is the only way, since the SDK did not provide ABAddressBookCopyPeopleWithNumber. I would like them to provide one.

0
source

The following method returns an array containing all contacts that have a given phone number. It doesn't matter if the phone number is just numbers or if it is formatted and contains a dash, etc.

This method took 0.02 seconds to search for 250 contacts on my iPhone 5 with iOS7.

#import <AddressBook/AddressBook.h> -(NSArray *)contactsContainingPhoneNumber:(NSString *)phoneNumber { /* Returns an array of contacts that contain the phone number */ // Remove non numeric characters from the phone number phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]] componentsJoinedByString:@""]; // Create a new address book object with data from the Address Book database CFErrorRef error = nil; ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error); if (!addressBook) { return [NSArray array]; } else if (error) { CFRelease(addressBook); return [NSArray array]; } // Requests access to address book data from the user ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {}); // Build a predicate that searches for contacts that contain the phone number NSPredicate *predicate = [NSPredicate predicateWithBlock: ^(id record, NSDictionary *bindings) { ABMultiValueRef phoneNumbers = ABRecordCopyValue( (__bridge ABRecordRef)record, kABPersonPhoneProperty); BOOL result = NO; for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) { NSString *contactPhoneNumber = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, i); contactPhoneNumber = [[contactPhoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]] componentsJoinedByString:@""]; if ([contactPhoneNumber rangeOfString:phoneNumber].location != NSNotFound) { result = YES; break; } } CFRelease(phoneNumbers); return result; }]; // Search the users contacts for contacts that contain the phone number NSArray *allPeople = (NSArray *)CFBridgingRelease(ABAddressBookCopyArrayOfAllPeople(addressBook)); NSArray *filteredContacts = [allPeople filteredArrayUsingPredicate:predicate]; CFRelease(addressBook); return filteredContacts; } 
0
source

All Articles