UIManagedDocument:在网络关闭时创建新文件时出错/保存(保存) [英] UIManagedDocument: Error/crash on creating new files when network is down (saving)

查看:181
本文介绍了UIManagedDocument:在网络关闭时创建新文件时出错/保存(保存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试保存一个新创建的UIManagedDocument到iCloud和网络中断(例如飞机模式)我得到以下错误崩溃(hexcodes和不可读的东西删除):

When I try to save a newly created UIManagedDocument to iCloud and the network is down (e.g. airplane mode) I get the following error(s) with a crash (hexcodes and unreadable stuff removed):

-[PFUbiquitySafeSaveFile waitForFileToUpload:](272): CoreData: Ubiquity:  <PFUbiquityPeerReceipt: ...>(0)
permanentLocation: <PFUbiquityLocation: ...>: /private/var/mobile/Library/Mobile Documents/XXXXXXXXXX~com~domain~AppName/TransactionLog/mobile.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/DocumentName/XXXXXXXXXXXXXXX/receipt.0.cdt
safeLocation: <PFUbiquityLocation: ...>: /private/var/mobile/Library/Mobile Documents/XXXXXXXXXX~com~domain~AppName/TransactionLog/mobile.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/DocumentName/XXXXXXXXXXXXXXX/mobile.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.0.cdt
currentLocation: <PFUbiquityLocation: ...>: /private/var/mobile/Library/Mobile Documents/XXXXXXXXXX~com~domain~AppName/TransactionLog/mobile.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/DocumentName/XXXXXXXXXXXXXXX/mobile.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.0.cdt

kv: (null)

Safe save failed for file, error: Error Domain=NSCocoaErrorDomain Code=512 "The file upload timed out." UserInfo=... {NSLocalizedDescription=The file upload timed out.}


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores.  It cannot perform a save operation.'
*** First throw call stack:
(...)
libc++abi.dylib: terminate called throwing an exception

我不知道这个错误,但它说,无法保存文档,因为没有可能的上传(当然,因为没有网络)。但我不明白为什么我不能捕获这个错误与保存完成处理程序:

I don't know this error but it says that document couldn't be saved because no upload is possible (of course, because there is no network). But I can't understand why I can't catch this error with the save completion handler:

[theDocumentToSave saveToURL:theDocumentToSave.fileURL
            forSaveOperation:UIDocumentSaveForCreating
           completionHandler:^(BOOL success) {
                 if (success) {
                     // Do somethings, go on, ...
                 } else {
                     // Catch error HERE, but this is never called!
                 }
}];


推荐答案

这不幸地代表了Core Data的iCloud集成。 UIManagedDocument 仍在尝试添加其数据存储,否则就没有这样做,因为没有网络连接。这不是它应该工作,但常见的故障或长时间的延迟让iCloud启动和运行Core Data。最坏的情况应该是 - 如你所期望的,你的完成块将被调用成功设置为 NO 。在这种情况下崩溃您的应用程序不是您的错,但这也意味着您可能很难做任何事情。

This unfortunately represents an internal bug in Core Data's iCloud integration. The UIManagedDocument is still trying to get its data store added, or else has just failed to do so, because there's no network connection. That's not how it's supposed to work, but it's common to have failures or long delays getting iCloud up and running with Core Data. The worst case should be-- as you expect-- that your completion block would be called with success set to NO. Crashing your app in this scenario is not your fault, but that also means you may have a hard time doing anything about it.

可以通过如下方式预测此崩溃:

You may be able to predict this crash by something like:

NSArray *persistentStores = theDocumentToSave.managedObjectContext.persistentStoreCoordinator.persistentStores;
if ([persistentStores count] == 0) {
    // exception is likely, should be at least 1
} else {
    // exception probably won't happen
}

这是一个黑客,但它不帮助你实际保存文件。此外,不能保证该文档以后可以成为可保存的。但是,它可以避免崩溃。

That's kind of a hack though, and it doesn't help you actually save the document. Plus, there's no guarantee that the document will become save-able at some later time. It could avoid crashes, though.

一般来说,Core Data plus iCloud不是最可靠的组合。我问iOS版本,因为iOS 6.x是,比iOS 5差。因为你已经在6,但我不能建议移动到6,希望更好的行为。

In general, Core Data plus iCloud is not the most reliable of combinations. I asked about the iOS version because iOS 6.x is, let's say, less bad than iOS 5. Since you're already on 6 though, I can't suggest moving to 6 in the hope of better behavior.

这篇关于UIManagedDocument:在网络关闭时创建新文件时出错/保存(保存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆