iphone - 将人员组添加到 ABAddressBookRef,组添加正常,但人员未添加到组?
<p><p>我有几行 Objective-C 代码,例如:</p>
<pre><code>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);
</code></pre>
<p>它运行正常,没有错误,组已添加到模拟器通讯簿但人没有添加到模拟器通讯簿。谁能告诉我哪里错了?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>根据 iOS 的通讯簿编程指南(下面的链接),通讯簿中必须存在人员记录,然后才能将其添加到组中。</p>
<p>“在可以将人员记录添加到组之前,它必须已经保存到通讯簿数据库。”</p>
<p> <a href="http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/500-DirectInteraction/DirectInteraction.html%23//apple_ref/doc/uid/TP40007744-CH6-SW4" rel="noreferrer noopener nofollow">http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/500-DirectInteraction/DirectInteraction.html%23//apple_ref/doc/uid/TP40007744-CH6-SW4</a> </p>
<p>所以也许这会起作用</p>
<pre><code>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);
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 将人员组添加到 ABAddressBookRef,组添加正常,但人员未添加到组?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/3776299/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/3776299/
</a>
</p>
页:
[1]