我有几行 Objective-C 代码,例如:
ABAddressBookRef addressBook;
CFErrorRef error = NULL;
addressBook = ABAddressBookCreate();
ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error);
ABRecordRef person = ABPersonCreate();
ABRecordSetValue(person,kABPersonFirstNameProperty,@"Huy 1111111",&error);
ABRecordSetValue(person,kABPersonLastNameProperty,@"AseDra",&error);
ABGroupAddMember(group, person, &error);
ABAddressBookAddRecord(addressBook, group, &error);
ABAddressBookSave(addressBook,&error);
它运行正常,没有错误,组已添加到模拟器通讯簿但人没有添加到模拟器通讯簿。谁能告诉我哪里错了?
Best Answer-推荐答案 strong>
根据 iOS 的通讯簿编程指南(下面的链接),通讯簿中必须存在人员记录,然后才能将其添加到组中。
“在可以将人员记录添加到组之前,它必须已经保存到通讯簿数据库。”
http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/500-DirectInteraction/DirectInteraction.html%23//apple_ref/doc/uid/TP40007744-CH6-SW4
所以也许这会起作用
ABAddressBookRef addressBook;
CFErrorRef error = NULL;
addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
ABRecordSetValue(person,kABPersonFirstNameProperty,@"Huy 1111111",&error);
ABRecordSetValue(person,kABPersonLastNameProperty,@"AseDra",&error);
// add the person record
ABAddressBookAddRecord(addressBook, person, &error);
ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error);
ABGroupAddMember(group, person, &error);
ABAddressBookAddRecord(addressBook, group, &error);
ABAddressBookSave(addressBook,&error);
关于iphone - 将人员组添加到 ABAddressBookRef,组添加正常,但人员未添加到组?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/3776299/
|