Finding people in Address Book via their phone number

Address Book on Mac OS X and iPhone unfortunately doesn’t normalize phone numbers when they are saved.  While AddressBook.app and iPhone’s “Contacts” app will appropriately display them, on the backend they could be saved as “1231231234”, or “123-123-1234”, or “(123) 123-1234”, or “123-(312)-1234”.

Yeah.  You get the point.

So this means we have to take a different approach.  One would be to possibly split the input phone number into three pieces — “123”, “123”, “1234” and then search from that.  Another is to just search by the last 4 digits of the phone number, using kABSuffixMatchCaseInsensitive and kABPhoneProperty.  From there you have to narrow down your result set by normalizing the phone numbers from the returned results, comparing to your entire phone number, then declaring an epic win.

Something like this should do the trick: http://pastie.org/423262

Blog comments powered by Disqus