- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在我的应用程序中使用 iCloud 来加载文本文件。加载文本文件时,当我调用 _UIDocument openWithCompletionHandler:^(BOOL success)
等时,iCloud 会调用此方法:
-(BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError **)outError {
NSLog(@"Library loadFromContents: state = %d", self.documentState);
if (!_books) {
_books = [[NSMutableArray alloc] init];
}
//if (self.documentState > 7) {
// NSLog(@"document is either savingError (4), EditingDisabled (8) or both (12)... will not load");
// return NO;
//}
self.books = [NSKeyedUnarchiver unarchiveObjectWithData:contents];
if ([_delegate respondsToSelector:@selector(libraryDocumentUpdated:)]) {
[_delegate libraryDocumentUpdated:self];
}
return YES;
}
现在最大的问题是当 documentState 为 8 (UIDocumentStateEditingDisabled) 或 12 (UIDocumentStateSavingError & UIDocumentStateEditingDisabled) 时。这通常会导致应用程序崩溃。如果 documentState > 7,即如果它是 8 或 12,我试图返回 NO,但这会导致根本不加载任何内容。
我想问题是如果 UIDocument 编辑被禁用或存在保存错误,它不会将任何内容加载到 self.books 中。
处理此类错误的最佳做法是什么?另外,为什么 Apple 在他们的示例代码中不建议在将数据加载到 UIDocument ( iCloud Docs ) 之前检查 documentState?我想我做的事情从根本上是错误的。
最佳答案
您是否实现了冲突管理?
在这些情况下你应该尝试一些事情然后重试加载文件第一个是检查是否
[NSFileVersion unresolvedConflictVersionsOfItemAtURL:]
有任何冲突,解决它们,重试打开文件,
[NSFileManager evictUbiquitousItemAtURL:]
和
[NSFileManager startDownloadingUbiquitousItemAtURL:]
如果还是打不开,请下载后再试。
关于iphone - iCloud 的 loadFromContents - 如何处理 UIDocumentStateSavingError 和 UIDocumentStateEditingDisabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8057019/
我有一个 iOS 应用程序,它实现了 UIDocument 的自定义子类,它在数据包、归档对象和图像上封装了一个文件包装器。我最初将实现转换为 UIDocument 以获得 iCloud 支持,但它太
这个问题在这里已经有了答案: EXC_BAD_ACCESS using iCloud on multiple devices (1 个回答) 关闭 9 年前。 我有一个使用 iCloud 文档存储的
我正在制作一个文本编辑器应用程序,它将其每个文档存储为 NSFileWrapper 目录,文档文本和文档标题作为目录中的单独文件。我希望 loadFromContents: (id) contents
我在我的应用程序中使用 iCloud 来加载文本文件。加载文本文件时,当我调用 _UIDocument openWithCompletionHandler:^(BOOL success) 等时,iCl
我有一个自定义 UIDocument 子类并实现了 loadFromContents:和 contentsForType: . 为了检测文档在另一台设备上被更改,我添加了一个代理到 loadFromC
我是一名优秀的程序员,十分优秀!