迭代 iPhone 地址簿导致地址簿 SQL 数据库损坏
我的应用程序有一个 NSOperation,可以打开 iphone 地址簿,循环访问用户的联系人并将姓名和电话号码复制到核心数据实体中。大多数情况下,这都可以正常工作,但很少会出现地址簿损坏且所有联系人丢失的情况。我没有对地址簿进行任何写入,所以不确定这是如何发生的。它不会抛出堆栈跟踪或使应用程序崩溃。我只是在再次运行我的应用程序后才注意到它。我在日志中看到以下内容...
CPSqliteStatementSendResults:文件已加密或不是数据库 checkResultWithStatement:文件已加密或不是 SELECT UID、标识符的数据库(SELECT value FROM ABMultiValueLabel WHERE ROWID = label)、value FROM ABMultiValue WHERE record_id = ? AND 属性+0 = ?;
...地址簿是空的。
是否可以仅通过读取地址簿或不正确关闭地址簿来将其丢弃?
My app has an NSOperation that opens the iphone addressbook, loops through the users's contacts and copies name and phone number into Core Data entities. Most of the time this works without issue but rarely it seems the address book gets corrupted and all contacts lost. I'm not doing any writing to the addressbook so not sure how this could happen. It doesn't throw a stack trace or crash the app. I only notice it after I run my app again. I see the following in the log...
CPSqliteStatementSendResults: file is encrypted or is not a database
checkResultWithStatement: file is encrypted or is not a database for SELECT UID, identifier, (SELECT value FROM ABMultiValueLabel WHERE ROWID = label), value FROM ABMultiValue WHERE record_id = ? AND property+0 = ?;
...and the addressbook is empty.
Is it possible to trash the addressbook just by reading from it or not closing out of it properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这件事以前就发生在我身上。
您正在从两个不同的线程访问同一个 AB 实例,并且地址簿不是线程安全的。
您需要使用 ABAddressBookCreate() 来获取要在每个单独线程上使用的实例。
来自文档:
重要:ABAddressBookRef 的实例不能由多个线程使用。每个线程都必须创建自己的实例。
您可以阅读更多相关信息此处。
我已经确认,如果您确实从多个线程读取数据,数据库将损坏,用户将失去所有联系人。
This exact thing happened to me before.
You are accessing the same AB instance from two different threads and the Address Book is not thread safe.
You ned to use ABAddressBookCreate() to get an instance to use on every individual thread.
From the documentation:
Important: Instances of ABAddressBookRef cannot be used by multiple threads. Each thread must make its own instance.
You can read more about it here.
I have confirmed that if you do read from multiple threads, the database will corrupt and the user wil loose all of their contacts.