无法使用ABGroupAddMember在iPhone中添加组中的联系人? [英] Unable to add contact in group using ABGroupAddMember in iphone?
本文介绍了无法使用ABGroupAddMember在iPhone中添加组中的联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码,但仍然无法在组中添加联系人信息,还有一件事情,它始终用于创建新组。我也想检查exisiting gruop是avaialble还是不可用。
I am using the following code but still its not able to add contact information in group and one more thing it always use to create new group. i also want to check that exisiting gruop is avaialble or not !!!!
无法添加群组中的联系人
Unable to add contact in group !!
ABRecordRef group = ABGroupCreate(); //create a group
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error); // set group's name
ABGroupAddMember(group, person, &error); // add the person to the group
ABAddressBookAddRecord(addressBook, group, &error); // add the group
ABAddressBookSave(addressBook, nil); //save the record
推荐答案
请在下面找到工作代码...
Please find the working code below ...
ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
ABRecordSetValue(aRecord, kABPersonFirstNameProperty,
CFSTR("Jijo"), &anError);
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();
BOOL isAdded = ABAddressBookAddRecord (
addressBook,
aRecord,
&error
);
if(isAdded){
NSLog(@"added..");
}
if (error != NULL) {
NSLog(@"ABAddressBookAddRecord %@", error);
}
error = NULL;
BOOL isSaved = ABAddressBookSave (
addressBook,
&error
);
if(isSaved){
NSLog(@"saved..");
}
if (error != NULL) {
NSLog(@"ABAddressBookSave %@", error);
}
CFRelease(aRecord);
CFRelease(firstName);
CFRelease(lastName);
CFRelease(addressBook);
不要忘记添加AddressBook.Framework。
Don't forget add the AddressBook.Framework.
参考文献: AddressBookProgrammingGuideforiPhone.pdf
同样的问题
http://www.iphonedevsdk.com/forum/iphone-sdk-development/12496-add-contact- address-book.html
这篇关于无法使用ABGroupAddMember在iPhone中添加组中的联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文