Add Contact to Existing Group programatically in iphone

自闭症网瘾萝莉.ら 提交于 2019-12-04 19:21:37

If we see the message:

CPSqliteStatementPerform: constraint failed for INSERT INTO ABGroupMembers (group_id, member_type, member_id) VALUES (?, ?, ?);
CPSqliteStatementReset: columns group_id, member_type, member_id are not unique for INSERT INTO ABGroupMembers (group_id, member_type, member_id) VALUES (?, ?, ?);

Also in documentation :

The ABAddressBook opaque type (whose instances are known as address books) provides a programming interface to the Address Book—a centralized database used by multiple applications to store personal information about people

(So, internally, this error is caused due to incorrect sqlite query.)

It indicates that there is some issue with ABGroupAddMember or ABAddressBookAddRecord(addressBookRef, group, &error); call.

The problem can be: We have group and person references already with us when we callABAddressBookGetGroupWithRecordID and ABAddressBookGetGroupWithRecordID functions.

Now, when ABAddressBookAddRecord is executed for both( person and group) it is adding them to addressbook but not updating their UniqueIds(id for person and group ref.) so at the time of ABGroupAddMember function call it has person and group with same ids which are added in ABGroupMembers table.

Please, try to print recordId for person and group after you add them to address book(and before you add them to group). if recordsIds are not updated then that is the cause, and you will need to fetch record for new recordId. Also check whether the new person and group are being added to addresbook or not.

*Currently, I do not mac access to verify my suggestion/answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!