2012-04-09 46 views
0

我有一個異常斷點集,當我調用 - (void)saveToURL:(NSURL *)url forSaveOperation:(UIDocumentSaveOperation)saveOperation completionHandler :(void(^)(BOOL success))completionHandler 我UIManagedDocument我有時會收到以下錯誤:使用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 

在我的控制檯登錄組織者,我看到這一點:

Apr 9 12:45:47 unknown District[232] : (Error) com.apple.UIKit.UIDocument: document: fileURL: file://localhost/var/mobile/Applications/F1A7026C-5ADD-4FAF-9C8C-887514F6EACA/Documents/PLDB/ documentState: [Normal] hit writing error: Error Domain=NSCocoaErrorDomain Code=134030 "The operation couldn’-t -b-e -c-o-m-p-l-e-t-e-d-. -(-C-o-c-o-a -e-r-r-o-r -1-3-4-0-3-0-.-)-" -U-s-e-r-I-n-f-o-=-0-x-5-c-1-6-8-0 -{-N-S-A-f-f-e-c-t-e-d-S-t-o-r-e-s-E-r-r-o-r-K-e-y-=-(^J -"-<-N-S-S-Q-L-C-o-r-e-: -0-x-5-b-2-7-4-0-> -(-U-R-L-: -f-i-l-e-:-/-/-l-o-c-a-l-h-o-s-t-/-v-a-r-/-m-o-b-i-l-e-/-A-p-p-l-i-c-a-t-i-o-n-s-/-F-1-A-7-0-2-6-C---5-A-D-D---4-F-A-F---9-C-8-C---8-8-7-5-1-4-F-6-E-A-C-A-/-D-o-c-u-m-e-n-t-s-/-P-L-D-B-/-S-t-o-r-e-C-o-n-t-e-n-t-/-p-e-r-s-i-s-t-e-n-t-S-t-o-r-e-)-"^J-)-, -N-S-U-n-d-e-r-l-y-i-n-g-E-r-r-o-r-=-0-x-5-e-8-0-2-0 -"-T-h-e -o-p-e-r-a-t-i-o-n -c-o-u-l-d-n’-t -b-e -c-o-m-p-l-e-t-e-d-. -(-C-o-c-o-a -e-r-r-o-r -4-.-)-"-, -N-S-F-i-l-e-P-a-t-h-=-/-v-a-r-/-m-o-b-i-l-e-/-A-p-p-l-i-c-a-t-i-o-n-s-/-F-1-A-7-0-2-6-C---5-A-D-D---4-F-A-F---9-C-8-C---8-8-7-5-1-4-F-6-E-A-C-A-/-D-o-c-u-m-e-n-t-s-/-P-L-D-B-/-S-t-o-r-e-C-o-n-t-e-n-t-/-p-e-r-s-i-s-t-e-n-t-S-t-o-r-e-} Apr 9 12:45:47 unknown District[232] : (Error) com.apple.UIKit.UIDocument: UIDocument unrecoverable error with description: The operation couldn’-t -b-e -c-o-m-p-l-e-t-e-d-. -(-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-) Apr 9 12:45:47 unknown District[232] : (Error) com.apple.UIKit.UIDocument: Failed to recover from error with description: The operation couldn’-t -b-e -c-o-m-p-l-e-t-e-d-. -(-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。

+0

你解決了這個問題嗎?我也看到這個錯誤。 – Macondo2Seattle 2012-04-20 23:53:16

+0

種。看到我剛剛發佈的答案。 – offex 2012-04-21 01:21:07

回答

1

我聽說過使用UIManagedDocument保存核心數據的不同觀點。有些人說,除非你第一次創建文檔,否則不要調用saveToUrl。不過,我記得從斯坦福大學的iOS課程中學習,saveToUrl ...當您明確想要保存時可以打電話。有人說用

[document updateChangeCount:UIDocumentChangeDone]

,它需要保存到通知的核心數據。有人說它會在自己的時間裏保存下來。有人說,你可以使用[背景obtainPermanentIDsForObjects:...]像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 ..調用,並且事情看起來工作得越來越好。如果由於某種原因必須保存文檔,請嘗試使用上述方法之一。