【问题标题】:Error saving core data using UIManagedDocument使用 UIManagedDocument 保存核心数据时出错
【发布时间】:2012-04-09 19:02:19
【问题描述】:

我设置了异常断点,当我调用 - (void)saveToURL:(NSURL *)url forSaveOperation:(UIDocumentSaveOperation)saveOperation completionHandler:(void (^)(BOOL success))completionHandler 在我的 UIManagedDocument 上,我有时会收到以下错误:

* thread #3: tid = 0x2003, 0x357a8238 libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 1.1
    frame #0: 0x357a8238 libobjc.A.dylib`objc_exception_throw
    frame #1: 0x3154a122 CoreData`-[NSPersistentStore(_NSInternalMethods) _preflightCrossCheck] + 758
    frame #2: 0x314bb296 CoreData`-[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 970
    frame #3: 0x31523286 CoreData`-[NSManagedObjectContext save:] + 522
    frame #4: 0x33d0ac5a UIKit`__84-[UIManagedDocument writeContents:toURL:forSaveOperation:originalContentsURL:error:]_block_invoke_0 + 30
    frame #5: 0x3152d3ee CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 74
    frame #6: 0x344fa7e6 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 26
    frame #7: 0x344fa646 libdispatch.dylib`dispatch_barrier_sync_f$VARIANT$mp + 62

在我的控制台登录管理器中,我看到了这个:

4 月 9 日 12:45:47 未知区[232]:(错误) com.apple.UIKit.UIDocument: 文件:文件网址: 文件://localhost/var/mobile/Applications/F1A7026C-5ADD-4FAF-9C8C-887514F6EACA/Documents/PLDB/ documentState:[正常]命中写入错误:错误 Domain=NSCocoaErrorDomain Code=134030 "操作无法'-t -b-e -完全的-。 -(-Cocoa -error -1-3-4-0-3-0-.-)-" -UserInfo-=-0-x-5-c-1-6-8-0 -{-NSAffectedStoresError-Key -=-(^J -"- -(-URL-: -file-:-/-/-localhost-/ -var-/-mobile-/-Applications-/-F-1-A-7-0-2-6-C---5-ADD---4-FAF---9-C-8-C ---8-8-7-5-1-4-F-6-EACA-/-Documents-/-PLDB-/-StoreContent-/-persistentStore-)-"^J-)-, -NSUnderlyingError-= -0-x-5-e-8-0-2-0 -"--操作 -could-n'-t -be -completed-。 -(-Cocoa -error -4-.-)-"-, -NSFilePath-=-/-var-/-mobile-/-Applications-/-F-1-A-7-0-2-6-C ---5-ADD---4-FAF---9-C-8-C---8-8-7-5-1-4-F-6-EACA-/-Documents-/-PLDB -/-StoreContent-/-persistentStore-} Apr 9 12:45:47 unknown District[232] : (错误) com.apple.UIKit.UIDocument:UIDocument 不可恢复 描述错误:操作无法'-t -b-e -完全的-。 -(-Cocoa -error -1-3-4-0-3-0-.-) -reason-: -(-null-) Apr 9 12:45:47 unknown District[232] : (Error) com. apple.UIKit.UIDocument:无法从错误中恢复,描述:操作无法 -t -be -完全的-。 -(-C-o-c-o-a -e-r-r-o-r -1-3-4-0-3-0-.-) -r-e-a-s-o-n-: -(-n-u-l-l-)

它不会每次都发生,所以可能是时间问题?它不会使我的程序崩溃,但会在我的异常断点处中断,并且我的块的成功值为 NO。

【问题讨论】:

  • 这个问题你解决了吗?我也看到了这个错误。
  • 那种。请参阅我刚刚发布的答案。

标签: ios core-data


【解决方案1】:

我听说过关于使用 UIManagedDocument 保存核心数据的不同意见。有人说永远不要调用 saveToUrl... 除非您第一次创建文档。但是,我记得从斯坦福 iOS 课程中了解到,当您明确想要保存时,可以调用 saveToUrl...。有人说要用

[document updateChangeCount:UIDocumentChangeDone]

通知核心数据需要保存。有人说它会在自己的时间里自救。有人说您可以使用 [context gainPermanentIDsForObjects: ...] 像 MSManagedObjectContext 上的以下类别来解决临时 ID 问题:

- (BOOL)obtainPermanentIDsForInsertedObjects:(NSError **)error
{
    NSSet * inserts = [self insertedObjects];

    if ([inserts count] == 0) return YES;

    return  [self obtainPermanentIDsForObjects:[inserts allObjects]
                                         error:error];
}

我希望我知道答案,但我认为我的问题是我调用 saveToUrl... 太多了。我删除了我所有的 saveToUrl.. 调用,除了第一个调用,事情似乎越来越好。如果您出于某种原因必须保存文档,请尝试上述方法之一。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多