Change ALL numbers in Address Book / Contacts
I'm trying to give a uniform change to all the numbers in my address book, I want to add my country code (+46) to all number starting with 0 and thought I'd make an app for this. The question is how to do t开发者_高级运维his in the best way, it seems kind of - hard.
The usual way seems to be through a person picker: http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/UI_Controllers.html#//apple_ref/doc/uid/TP40007744-CH5-SW4 - but this means the user has to pick the contact that it wants to change, which must be an overcomplicated way of doing this.
Is there a way to loop through all the numbers in the address book, change them/it, and then put them back?
Thank you in advance, Tobias Tovedal.
Yes, you can loop through the all records and can edit the records from the addressbook. Following is the example to get all records from addressbook:
NSArray *array= (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
Following is the code to edit a particular record from the addressbook on the basis of person's recordID:
ABAddressBookRef ab = ABAddressBookCreate();
ABRecordID id = ABRecordGetRecordID(person);
ABRecordRef newPerson = ABAddressBookGetPersonWithRecordID(ab, id);
if(newPerson != NULL){
if(![firstName.text isEqual:firstname]){
ABRecordRemoveValue(newPerson, kABPersonFirstNameProperty,nil);
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, firstName.text,nil);
}
}
ABAddressBookSave(ab,nil);
You can either take the records in array and then change the values of phone number or traverse through the records one by one. you need to take care while taking the phone number of a person as a single person can have multiple phone numbers so, you need to use ABMultiValueRef while getting the phone number which will give all the phone numbers of a person.
精彩评论