연락처가 성공적으로 업데이트되었지만 연락처 애플리케이션에 업데이트 된 이름이 표시되지 않는 등의 성공 메시지가 표시됩니다.주소록의 연락처 이름을 프로그래밍 방식으로 업데이트 하시겠습니까?
연락처 이름을 업데이트하는 방법은 아래와 같습니다.
-(void)updateAddressBook
{
CFErrorRef *error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL,error);
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
CFArrayRef sortedPeople =ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName);
CFIndex number = CFArrayGetCount(sortedPeople);
NSString *firstName;
NSString *phoneNumber ;
for(int i=0;i<number;i++)
{
ABRecordRef person = CFArrayGetValueAtIndex(sortedPeople, i);
firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
phoneNumber = (__bridge NSString *) ABMultiValueCopyValueAtIndex(phones, 0);
ABRecordID recordID1 = ABRecordGetRecordID(person);
NSLog(@"%d", recordID1);
ABRecordRef record = ABAddressBookGetPersonWithRecordID(addressBook, recordID1);
NSNumber *recordId = [NSNumber numberWithInteger:ABRecordGetRecordID(record)];
NSLog(@"recordId:- %d",[recordId intValue]);
bool didSet;
//update First name
didSet = ABRecordSetValue(record, kABPersonFirstNameProperty, (__bridge CFTypeRef)([NSString stringWithFormat:@"Person Name"]) , nil);
if (didSet) {
NSLog(@"contact is successfully updated");
}else{
NSLog(@"error");
}
CFStringRef firstName;
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSLog(@"%@",firstName);
ABAddressBookSave(addressBook, error)
}
}
어떤 아이디어가 있습니까? 나는 당신의 대답을 기다리고 있습니다!
이 데모 http://www.theappguruz.com/blog/ios-manage-contacts-from-your-application에게 –
감사를 시도 @Jecky -
다음을 시도 하지만 난 ABPersonViewController를 열지 않고 연락처를 편집했습니다 –
시도해보십시오 http://stackoverflow.com/questions/7577005/how-to-modify-a-contact-number-in-address-book-programatically – sandy