Iterate over iPhone Address book calling sql db corrupt address book

My application has NSOperation, which opens the iphone address book, scrolls user contacts and copies the name and phone number into Core Data objects. In most cases, this works without problems, but it rarely seems that the address book is corrupted and all contacts are lost. I do not write in the address book, so I do not know how this can happen. It does not throw a stack trace and does not crash the application. I noticed this only after I started the application again. I see the following in a magazine ...

CPSqliteStatementSendResults: file is encrypted or not a database checkResultWithStatement: file is encrypted or not a database for SELECT UID, identifier, (SELECT FROM value ABMultiValueLabel WHERE ROWID = label), value FROM ABMultiValue WHERE record_id =? And property + 0 = ?;

... and the address book is empty.

Is it possible to delete an address book simply by reading it or not closing it correctly?

+4
source share
1 answer

This is what happened to me before.

You access the same AB instance from two different threads, and the address book is not thread safe.

You need to use ABAddressBookCreate () to get an instance for use in each individual thread.

From the documentation: Important: Instances of ABAddressBookRef cannot be used by multiple threads. Each thread must make its own instance. Important: Instances of ABAddressBookRef cannot be used by multiple threads. Each thread must make its own instance.

Learn more about this here .

I confirmed that if you read from multiple threads, the database will be corrupted and the user will lose all his contacts.

+3
source

Source: https://habr.com/ru/post/1382996/


All Articles