尝试在我的 viewdidload 中使用以下代码,但我似乎无法将测试联系人加载到我的测试 iphone(运行 IOS 6)上。关于为什么这不起作用的任何建议?
CFErrorRef* error;
// create address book record
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil,error);
// 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);