我正在与ABAddressBook
. 我查看了 API 文档,但找不到任何与创建新的ABRecord
. 但在 中ABAddressBook
,有一种方法ABAddressBookAddRecord
可用。但我没有找到任何可用于创建新记录的 API。有没有办法做到这一点?
此致,
穆罕默德·萨迪克。
我正在与ABAddressBook
. 我查看了 API 文档,但找不到任何与创建新的ABRecord
. 但在 中ABAddressBook
,有一种方法ABAddressBookAddRecord
可用。但我没有找到任何可用于创建新记录的 API。有没有办法做到这一点?
此致,
穆罕默德·萨迪克。
// 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);