我有几行 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);
它运行正常,没有错误,组已添加到模拟器通讯簿但人没有添加到模拟器通讯簿。谁能告诉我哪里错了?
根据 iOS 的通讯簿编程指南(下面的链接),通讯簿中必须存在人员记录,然后才能将其添加到组中。
“在可以将人员记录添加到组之前,它必须已经保存到通讯簿数据库。”
所以也许这会起作用
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/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |