0
我必須在後臺進程中從服務器下載多個文件。 爲此,我正在使用NSOperationQueue
。在下載期間,我需要保持下載已經開始&完成。爲此,我一直在使用核心數據。 我一直在使用下面的方法: 對應每個文件有NSManagedObject
。與NSOperationQueue同步執行多個NSOpeartion
- 所以之前下載開始我在覈心數據保存狀態的文件作爲「入門」
- 的NSOperation子類there.Instance爲每個地方我通過那麼managedObject實例。它被添加到
NSOperationQueue
文件創建。 - 然後在
NSOperation
子類的main()方法中,我做了實際的文件下載。 - 當下載完成時,我將核心數據中的狀態保存爲「已完成」。
這適用於單個文件,但對於多個文件,我在for循環中執行第1步到第4步。 這破壞NSMangedObject
傳遞給NSOperation
子類第二次迭代的for循環 我這是怎麼叫它
for(NSManagedObject *objToDownload in objectArr){
NSManagedObjectContext *ctx = [[NSManagedObjectContext alloc] init];
[ctx setPersistentStoreCoordinator: [[[UIApplication sharedApplication] delegate] persistentStoreCoordinator]];
offlineManagerObj = [[OfflineFileManager alloc]initWithManagedObj:objToDownload delegate:self tempOfflineAccessPath:[objToDownload valueForKey:@"path"] objContext:ctx];
[queue setMaxConcurrentOperationCount:1];
[queue addOperation:offlineManagerObj];
[ctx release];
}
我得到了以下的崩潰日誌
#0 0x31b6b4b0 in ___forwarding___()
#1 0x31ae2180 in __forwarding_prep_0___()
#2 0x363b904e in -[_PFArray dealloc]()
#3 0x363b6b80 in -[_PFArray release]()
#4 0x31acd1a0 in CFRelease()
#5 0x31acfeba in _CFAutoreleasePoolPop()
#6 0x310ae1ca in -[NSAutoreleasePool release]()
#7 0x370bff0e in _UIApplicationHandleEvent()
#8 0x35bc0e76 in PurpleEventCallback()
#9 0x31b3fa96 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__()
#10 0x31b4183e in __CFRunLoopDoSource1()
#11 0x31b4260c in __CFRunLoopRun()
#12 0x31ad2ec2 in CFRunLoopRunSpecific()
#13 0x31ad2dca in CFRunLoopRunInMode()
#14 0x35bc041e in GSEventRunModal()
#15 0x35bc04ca in GSEventRun()
#16 0x370ead68 in -[UIApplication _run]()
#17 0x370e8806 in UIApplicationMain()
#18 0x00002482 in main (argc=1, argv=0x2fdff494) at /Projects/iOS_Universal/main.m:14
我甚至嘗試設置NSZombieEnabled
,但同樣沒有幫助我得到哪個對象是過度發佈的
您不需要核心數據來跟蹤下載狀態。只需檢查NSOperation標誌'執行'和'完成'。 – Jano
但是,我也需要通過NSMangedObject文件我需要download.Basically該對象正在被破壞。 – Ritika