Icloud 在两个不同的设备上保存相同的UIManagedDocument会产生错误

Icloud 在两个不同的设备上保存相同的UIManagedDocument会产生错误,icloud,uimanageddocument,Icloud,Uimanageddocument,是否应在我的两台设备上打开相同的UIManagedDocument,然后保存(使用以下代码): 我被告知,UIManagedDocuments documentState已更改为UIDocumentStateSavingError,然后我收到以下错误: CoreData: error: (1) I/O error for database at /var/mobile/Applications/some-long-id/Documents/Read.dox/StoreContent.nosync

是否应在我的两台设备上打开相同的
UIManagedDocument
,然后保存(使用以下代码):

我被告知,
UIManagedDocument
s documentState已更改为
UIDocumentStateSavingError
,然后我收到以下错误:

CoreData: error: (1) I/O error for database at /var/mobile/Applications/some-long-id/Documents/Read.dox/StoreContent.nosync/persistentStore.  SQLite error code:1, 'cannot rollback - no transaction is active'
2013-05-14 16:30:09.062 myApp[11711:4d23] -[_PFUbiquityRecordImportOperation main](312): CoreData: Ubiquity:  Threw trying to get the knowledge vector from the store: <NSSQLCore: 0x1e9e2680> (URL: file://localhost/var/mobile/Applications/some-long-id/Documents/Read.dox/StoreContent.nosync/persistentStore)
CoreData:错误:(1)位于/var/mobile/Applications/some long id/Documents/Read.dox/StoreContent.nosync/persistentStore的数据库的I/O错误。SQLite错误代码:1,“无法回滚-没有活动的事务”
2013-05-14 16:30:09.062我的应用程序[11711:4d23]-[u pfubiquityrecordomportoperation main](312):CoreData:Ubiquity:throw试图从商店获取知识向量:(URL:file://localhost/var/mobile/Applications/some-long-id/Documents/Read.dox/StoreContent.nosync/persistentStore)
有人知道为什么会发生这种错误吗?

有几件事

我认为在两个不同的设备上保存同一个文档是一种误导,因为它实际上会在每个设备上处理您的数据库的本地副本-只有事务日志才会上载到iCloud

其次,我可能会感到困惑,但我在上面的代码片段中没有看到任何指示您正在执行保存的内容(除非它是由其中一个调用触发的,或者发生自动保存)

该代码段似乎正在做的是:

  • 在数据库文档的子MOC线程上,运行以下块 密码
  • 这段代码是纯UI相关的东西, 与数据库无关?唯一可能 要去DB的是cellForRowAtIndexPath——这通常是 只能执行读取操作,而不是其他操作 这需要节约
唯一的另一件事。。。。如果上面的代码确实触发了保存,那么作为performBlockAndWait执行该操作可能会有问题。UIManagedDocument保存例程以异步方式进行操作,但它们需要先执行运行循环,然后才能真正有机会运行异步部分。。。因此,通过在继续之前阻塞,实际上可能会阻止执行实际的保存或其他操作

我在这里疯狂地猜测,但是我已经了解了保存托管文档的足够多的知识,知道要真正小心从哪个线程调用东西,并且在发出保存请求之后,要允许运行循环有机会真正执行它。公平地说,调用saveToURL时,这只是一个问题:在一个方法中或在一个循环中重复,在这种情况下,保存的所有异步部分都会排队并在最后执行,通常会产生非常滑稽的效果

CoreData: error: (1) I/O error for database at /var/mobile/Applications/some-long-id/Documents/Read.dox/StoreContent.nosync/persistentStore.  SQLite error code:1, 'cannot rollback - no transaction is active'
2013-05-14 16:30:09.062 myApp[11711:4d23] -[_PFUbiquityRecordImportOperation main](312): CoreData: Ubiquity:  Threw trying to get the knowledge vector from the store: <NSSQLCore: 0x1e9e2680> (URL: file://localhost/var/mobile/Applications/some-long-id/Documents/Read.dox/StoreContent.nosync/persistentStore)