开发者

Creating a new ABRecord

开发者 https://www.devze.com 2022-12-13 23:23 出处:网络
I am working with ABAddressBook. I have checked out the API docs but could not find any API related to creating开发者_如何学JAVA a new ABRecord. But in ABAddressBook, a method ABAddressBookAddRecord

I am working with ABAddressBook. I have checked out the API docs but could not find any API related to creating开发者_如何学JAVA a new ABRecord. But in ABAddressBook, a method ABAddressBookAddRecord is available. But I didnt find any APIs available to create a new record. Is there any way to do this?

Best Regards,

Mohammed Sadiq.


// 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消