创建新的 ABRecord

发布于 2024-08-15 04:42:56 字数 244 浏览 13 评论 0原文

我正在使用 ABAddressBook。我已经检查了 API 文档,但找不到任何 与创建新的 ABRecord 相关的 API。但在 ABAddressBook 中,有一个方法 ABAddressBookAddRecord 可用。但我没有找到任何可用于创建新记录的 API。有什么办法可以做到这一点吗?

最好的问候,

穆罕默德·萨迪克。

I am working with ABAddressBook. I have checked out the API docs but could not find any
API related to creating 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煮茶煮酒煮时光 2024-08-22 04:42:56
// 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);
// 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文