JPContactArchive is a project to demonstrate the use of one method: updateContact.
updaateContact uses stored values for a contact’s name, phone number, record ID and selected number index to update the phone number if it has changed.
- The record ID is an integer that essentially stores what number a person was added to the address book. The first added contact has record ID 1. docs
- The number index is numbered phone number is selected. For a contact with three numbers labeled iPhone, Home and Work, work would have number index 2 (starting at digit 0).
- Run the app with at least one contact with at least one phone number.
- Add them using the change contact button.
- Then leave the app and change the contact’s phone number that you selected.
- Come back to the app and the contact’s number is updated to the new one.
If there are multiple phone numbers only the recorded one is changed as the index of that number is cached.
How to Use
Every line of code excluding the method -updateContact is probably rather useless to any given project. Take the meat of updateContact and integrate it how you wish.
- Update to allow use of emails as necessary to support iMessage. (This is one reason why the phone number is stored as a NSString instead of NSNumber.)
I am bias to use this project for phone numbers only, as they are currently the only way to text message. You can easily adapt this to use another ABPropertyID for say, addresses if you deal with maps and contacts instead of phone numbers and contacts.
My app Bombr uses this code to automatically update changed contact numbers. As it is open source you may also use it commercially.