I am trying to find a way to amend an Address Book record which will work the same on all OSs (post 3.0, anyway) and correctly sync with Google Contacts/Outlook.
I tried writing the new email data to the existing record and writing it back out. This worked fine for several days when testing on iOS4, and I thought I was home and dry, but I found that on iOS 3.1.3 the ABAddressBookSave call throws a SQLite database error, complaining about trying to create duplicate entries:
CPSqliteStatementPerform: constraint failed for INSERT INTO ABPerson (ROWID, First, Last, Middle, Organization, Kind, Nickname, P开发者_如何学Crefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, StoreID, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); CPSqliteStatementReset: PRIMARY KEY must be unique
When I tried deleting the old entry and replacing it with an entirely new one instead, it caused duplicate email address entries (I am guessing this is because the sync process saw it as a new record and tried to merge them, maybe when synching with Google)
The Apple docs ("Address Book Programming Guide for iPhone") gives examples for creating and deleting entries, but not for partial updating.
Any ideas? All suggestions gratefully received
Cheers
Peter Johnson
Soluble Apps (www.solubleapps.com)
Its looking like I may have solved this myself.
I was doing ABAddressBookAddRecord on the record after it had been altered- whilst this makes sense when its a new record that has just been created, it was probably the cause of the SQL error when it was an old record that had been updated, creating two entries for it in the address book.
I still have to test this theory on 3.1.3 (when I can borrow my brother's touch :)), but I hope this helps someone.
精彩评论