菜鸟教程小白 发表于 2022-12-13 16:19:42

iphone - 将人员组添加到 ABAddressBookRef,组添加正常,但人员未添加到组?


                                            <p><p>我有几行 Objective-C 代码,例如:</p>

<pre><code>ABAddressBookRef addressBook;
CFErrorRef error = NULL;
addressBook = ABAddressBookCreate();
ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,@&#34;My Group&#34;, &amp;error);

ABRecordRef person = ABPersonCreate();
ABRecordSetValue(person,kABPersonFirstNameProperty,@&#34;Huy 1111111&#34;,&amp;error);
ABRecordSetValue(person,kABPersonLastNameProperty,@&#34;AseDra&#34;,&amp;error);
ABGroupAddMember(group, person, &amp;error);

ABAddressBookAddRecord(addressBook, group, &amp;error);

ABAddressBookSave(addressBook,&amp;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,@&#34;Huy 1111111&#34;,&amp;error);
ABRecordSetValue(person,kABPersonLastNameProperty,@&#34;AseDra&#34;,&amp;error);

// add the person record
ABAddressBookAddRecord(addressBook, person, &amp;error);

ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,@&#34;My Group&#34;, &amp;error);
ABGroupAddMember(group, person, &amp;error);
ABAddressBookAddRecord(addressBook, group, &amp;error);

ABAddressBookSave(addressBook,&amp;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]
查看完整版本: iphone - 将人员组添加到 ABAddressBookRef,组添加正常,但人员未添加到组?