【发布时间】:2018-11-21 06:45:47
【问题描述】:
我正在使用将联系人添加到地址簿的 iPhone 应用程序。我已经能够将联系人添加到通讯簿,但我面临的问题是在将联系人记录添加到我创建的组时。
联系人是在已创建的组以外的所有联系人下创建的。下面是我用过的代码
// create address book record
ABAddressBookRef addressBook = ABAddressBookCreate();
// create a person
ABRecordRef person = ABPersonCreate();
// first name of the new person
ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil);
// his last name
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil);
//add the new person to the record
ABAddressBookAddRecord(addressBook, person, nil);
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
//save the record
ABAddressBookSave(addressBook, nil);
// relase the ABRecordRef variable
CFRelease(person);
【问题讨论】:
-
你的意思是你不能将人添加到组对吗?
-
是的,此人未添加到组中,但已添加到所有联系人中。
标签: iphone objective-c xcode