我正在使用添加聯繫人到地址簿的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);
的代碼,我將不勝感激這方面
感謝提供任何幫助!
你的意思是你不能將人添加到組中嗎? – dks1725 2011-04-19 07:04:18
是這個人沒有被添加到該組,但它被添加到所有聯繫人。 – alanvabraham 2011-04-19 07:28:04