2009-12-16 4 views
0

ABAddressBook으로 작업 중입니다. API 문서를 확인했지만 새 ABRecord을 만드는 데 관련된 API를 찾을 수 없습니다. 그러나 ABAddressBook에는 ABAddressBookAddRecord 메서드를 사용할 수 있습니다. 하지만 새로운 레코드를 만들 수있는 API를 찾지 못했습니다. 이 일을 할 수있는 방법이 있습니까?새 ABRecord 만들기

모하메드 사디크.

+3

이전 질문에 대한 답변을 수락하면 사람들이 귀하의 질문에 답변 할 확률이 높습니다. –

답변

4
// create new address book person record 
ABRecordRef aRecord = ABPersonCreate(); 
CFErrorRef anError = NULL; 
// adjust record firstname 
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, 
           CFSTR("Jijo"), &anError); 
// adjust record lastname 
ABRecordSetValue(aRecord, kABPersonLastNameProperty, 
           CFSTR("Pulikkottil"), &anError); 
if (anError != NULL) { 
    NSLog(@"error while creating.."); 
} 

CFStringRef firstName, lastName; 
firstName = ABRecordCopyValue(aRecord, kABPersonFirstNameProperty); 
lastName = ABRecordCopyValue(aRecord, kABPersonLastNameProperty); 

ABAddressBookRef addressBook; 
CFErrorRef error = NULL; 
addressBook = ABAddressBookCreate(); 

// try to add new record in the address book 
BOOL isAdded = ABAddressBookAddRecord (addressBook, 
             aRecord, 
             &error 
); 

// check result flag 
if(isAdded){ 
    NSLog(@"added.."); 
} 
// check error flag 
if (error != NULL) { 
    NSLog(@"ABAddressBookAddRecord %@", error); 
} 
error = NULL; 

// save changes made in address book 
BOOL isSaved = ABAddressBookSave (
           addressBook, 
           &error 
); 

// check saved flag 
if(isSaved){ 
    NSLog(@"saved.."); 
} 

// check error flag 
if (error != NULL) { 
    NSLog(@"ABAddressBookSave %@", error); 
} 

CFRelease(aRecord); 
CFRelease(firstName); 
CFRelease(lastName); 
CFRelease(addressBook);