所以我调用这个方法:
- (void)newPersonViewController:(ABNewPersonViewController*)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person
它返回一个 ABRecordRef。但是我看不到使用 ABGroupAddMember 的组。
如果我手动创建 ABRecordRef,我可以设置组,但不能使用委托方法返回的人员对象。
例如,此代码有效(从此处的帖子借用,找不到链接):
CFErrorRef error = NULL;
// 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);
ABAddressBookSave(addressBook, &error);
ABRecordRef group = ABGroupCreate(); //create a group
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error); // set group's name
ABAddressBookAddRecord(addressBook, group, &error); // add the group
ABAddressBookSave(addressBook, &error);
ABGroupAddMember(group, person, &error); // add the person to the group
ABAddressBookSave(addressBook, &error);
//save the record
ABAddressBookSave(addressBook, nil);
// relase the ABRecordRef variable
CFRelease(person);
如何使该代码与返回的 Person ABRecordRef 对象一起使用?
谢谢。