ABAddressBook - 多个地址簿?
我正在构建一个从在线源同步联系人的应用程序。到目前为止,一切正常......当手机有一个地址簿时:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef group1 = ABGroupCreate();
ABRecordSetValue(group1,kABGroupNameProperty,@"Group1",nil);
ABAddressBookAddRecord(addressBook,group1,nil);
ABAddressBookSave(addressBook,nil);
ABRecordRef person = ABPersonCreate();
// Edit person values...
ABGroupAddMember(group1,person,nil);
ABAddressBookAddRecord(addressBook,person,nil);
ABAddressBookSave(addressBook,nil);
CFRelease(person);
CFRelease(addressBook);
但是当手机已经有多个地址簿时,就会出现问题。我正在一部手机上进行测试,该手机有一个用于所有联系人的地址簿,一个用于 Gmail 等。当我以上述方式添加联系人时,它会将其添加到 Gmail 地址簿,并在此过程中删除“Group1”标识符从接触。有没有办法可以更改 ABAddressBookRef 以指向手机内的特定地址簿?
I am building an app which syncs contacts from an online source. Everything works fine so far...when the phone has one address book:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef group1 = ABGroupCreate();
ABRecordSetValue(group1,kABGroupNameProperty,@"Group1",nil);
ABAddressBookAddRecord(addressBook,group1,nil);
ABAddressBookSave(addressBook,nil);
ABRecordRef person = ABPersonCreate();
// Edit person values...
ABGroupAddMember(group1,person,nil);
ABAddressBookAddRecord(addressBook,person,nil);
ABAddressBookSave(addressBook,nil);
CFRelease(person);
CFRelease(addressBook);
The problem occurs, however when the phone already has multiple address books. I am testing on a phone that has one address book for All Contacts, one for Gmail, etc. When I add a contact in the above manner, it adds it to the Gmail address book, and in the process strips the "Group1" identifier from the contact. Is there a way I can change the ABAddressBookRef to point to a specific address book within the phone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 引用、
ABAddressBookCreate
始终返回从系统地址簿数据库填充的地址簿对象。这意味着即使您有多个用于与其交互的ABAddressBook
实例,也只有一本地址簿。According to the reference,
ABAddressBookCreate
always returns an address book object populated from the system's address book database. Which means there is only ever one address book, even if you have multiple instances ofABAddressBook
that you use to interact with it.迈克,你可能想看看这篇文章:
在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource
虽然我相信亚历克斯是对的,只有一本地址簿,该地址簿可能由多个来源(ABSource)组成。而且,在 iOS 4+ 中,可以专门识别和操作特定的源。
Mike, you might want to take a look at this post:
Obtaining Specific ABSource from ABAddressBook in iOS 4+
Although I believe Alex is right that there is only ever one address book, that address book may consist of multiple sources (ABSource). And, in iOS 4+ it is possible to specifically identify and manipulate particular sources.