Ios `NSPersistentStoreCoordinator removePersistentStore:`使用永久对象ID时挂起

Ios `NSPersistentStoreCoordinator removePersistentStore:`使用永久对象ID时挂起,ios,core-data,ios7,Ios,Core Data,Ios7,我最近在我们的应用程序中遇到了一个问题,这是由于使用了临时的nsmanagedobjections。为了响应网络请求,映射操作将托管对象插入专用队列MOC,然后将其保存到根MOC(分配了persistentStoreCoordinator的MOC) 我们知道没有永久性身份证可能会导致问题,但是我们没有遇到任何问题,所以我们坚持了下来 我最终偶然发现了一个临时身份证的问题,并决定换成永久身份证。需要明确的是:每次作为映射操作的一部分插入新对象时,我们都会获得永久ID 问题解决了,快乐的日子!别那么

我最近在我们的应用程序中遇到了一个问题,这是由于使用了临时的
nsmanagedobjections
。为了响应网络请求,映射操作将托管对象插入专用队列MOC,然后将其保存到根MOC(分配了
persistentStoreCoordinator
的MOC)

我们知道没有永久性身份证可能会导致问题,但是我们没有遇到任何问题,所以我们坚持了下来

我最终偶然发现了一个临时身份证的问题,并决定换成永久身份证。需要明确的是:每次作为映射操作的一部分插入新对象时,我们都会获得永久ID

问题解决了,快乐的日子!别那么快。。。在iOS 7.1(8.4可以正常工作)下,对
NSPersistentStoreCoordinator的调用将删除PersistentStore:
现在无限期挂起。当用户注销时,我们将此作为核心数据堆栈拆卸的一部分进行操作(以清除所有数据)

以下是我们的持久性管理器的相关代码:

- (void)reset {
    FCYWeakifySelf;
    [self.managedObjectContext performBlockAndWait:^{
        FCYStrongifySelfInto(strongSelf);

        strongSelf.managedObjectContext = nil;
        strongSelf.persistentStoreManagedObjectContext = nil;

        for (NSPersistentStore *store in strongSelf.persistentStoreCoordinator.persistentStores) {
            NSError *error = nil;
            BOOL didRemoveStore = [strongSelf.persistentStoreCoordinator removePersistentStore:store error:&error];
            FCYAssert(didRemoveStore, @"Failed to remove persistent store: %@\n%@", [error localizedDescription], [error userInfo]);
        }

        strongSelf.persistentStoreCoordinator = nil;
        strongSelf.managedObjectModel = nil;
    }];

    [self initializeCoreData];
    [self notifyDelegates];
}

- (void)initializeCoreData {
    FCYAssert(!self.managedObjectModel, @"CoreData has already been initialized");

    NSBundle *bundle = [NSBundle bundleForClass:[TTPersistenceManager class]];
    self.managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:@[bundle]];
    self.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];

    NSError *error = nil;
    NSPersistentStore *store = [self.persistentStoreCoordinator addPersistentStoreWithType:[self storageType] configuration:nil URL:nil options:nil error:&error];
    FCYAssert(store != nil, @"Failed create persistent store: %@\n%@", [error localizedDescription], [error userInfo]);

    self.persistentStoreManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    self.persistentStoreManagedObjectContext.persistentStoreCoordinator = self.persistentStoreCoordinator;
    self.persistentStoreManagedObjectContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy;

    self.managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
    self.managedObjectContext.parentContext = self.persistentStoreManagedObjectContext;
    self.managedObjectContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy;
}
当应用程序挂起且我停止执行时,这是回溯:

* thread #1: tid = 0x38ee8e, 0x0000000112f6551a libsystem_kernel.dylib`semaphore_wait_trap + 10, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x0000000112f6551a libsystem_kernel.dylib`semaphore_wait_trap + 10
    frame #1: 0x0000000112bde7b4 libdispatch.dylib`_dispatch_thread_semaphore_wait + 16
    frame #2: 0x0000000112bdc3a2 libdispatch.dylib`_dispatch_barrier_sync_f_slow + 321
    frame #3: 0x000000010fb08f92 CoreData`_perform + 114
    frame #4: 0x000000010fb0b7b8 CoreData`-[NSManagedObjectContext(_NestedContextSupport) managedObjectContextDidUnregisterObjectsWithIDs:] + 72
    frame #5: 0x000000010fae0d2a CoreData`-[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 1706
    frame #6: 0x000000010fb0ff33 CoreData`-[NSManagedObjectContext(_NSInternalNotificationHandling) _processChangedStoreConfigurationNotification:] + 2771
    frame #7: 0x000000010fb71ee4 CoreData`__95-[NSManagedObjectContext(_NSInternalNotificationHandling) _sendOrEnqueueNotification:selector:]_block_invoke + 84
    frame #8: 0x000000010fb08c7b CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 107
    frame #9: 0x000000010fb08bc4 CoreData`-[NSManagedObjectContext performBlockAndWait:] + 132
    frame #10: 0x000000010fb0f2f7 CoreData`-[NSManagedObjectContext(_NSInternalNotificationHandling) _sendOrEnqueueNotification:selector:] + 231
    frame #11: 0x000000011289dd9c CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #12: 0x000000011280051d CoreFoundation`_CFXNotificationPost + 2381
    frame #13: 0x000000011027e7fa Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 68
    frame #14: 0x000000010fac06bc CoreData`-[NSPersistentStoreCoordinator(_NSInternalMethods) _postStoresChangedNotificationsForStores:changeKey:options:] + 220
    frame #15: 0x000000010fb0e5d6 CoreData`-[NSPersistentStoreCoordinator removePersistentStore:error:] + 278
    frame #16: 0x000000010e4bc430 Wingtip`__29-[TTPersistenceManager reset]_block_invoke(.block_descriptor=<unavailable>) + 528 at TTPersistenceManager.m:67
    frame #17: 0x000000010fb08c7b CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 107
    frame #18: 0x000000010fb08bc4 CoreData`-[NSManagedObjectContext performBlockAndWait:] + 132
    frame #19: 0x000000010e4bc17d Wingtip`-[TTPersistenceManager reset](self=0x00007ff441604e50, _cmd=0x0000000118cfb867) + 237 at TTPersistenceManager.m:59
    frame #20: 0x000000010e1dee19 Wingtip`-[WTGatekeeper resetPersistenceManager](self=0x00007ff44195a520, _cmd=0x000000010e8c079e) + 121 at WTGatekeeper.m:118
    frame #21: 0x000000011283df1c CoreFoundation`__invoking___ + 140
    frame #22: 0x000000011283ddc4 CoreFoundation`-[NSInvocation invoke] + 308
    frame #23: 0x000000010e48d141 Wingtip`-[TTStateMachine callTargetsWithEvent:state:](self=0x00007ff44177d2f0, _cmd=0x000000010e8e89a5, event=TTStateMachineEventDidEnter, state=0x000000010ea12f28) + 977 at TTStateMachine.m:277
    frame #24: 0x000000010e48aa59 Wingtip`-[TTStateMachine transitionToState:error:](self=0x00007ff44177d2f0, _cmd=0x000000010e8c0919, state=0x000000010ea12f28, error=0x00007fff51a2d168) + 521 at TTStateMachine.m:105
    frame #25: 0x000000010e1e0a66 Wingtip`-[WTAuthenticationStateMachine transitionToState:error:](self=0x00007ff44177d2f0, _cmd=0x000000010e8c0919, state=0x000000010ea12f28, error=0x00007fff51a2d168) + 454 at WTAuthenticationStateMachine.m:91
    frame #26: 0x000000010e48ac08 Wingtip`-[TTStateMachine transitionToState:](self=0x00007ff44177d2f0, _cmd=0x000000010e8c0746, state=0x000000010ea12f28) + 168 at TTStateMachine.m:119
    frame #27: 0x000000010e1e3118 Wingtip`__33-[WTAuthenticateBehavior signOut]_block_invoke(.block_descriptor=<unavailable>, alertView=0x00007ff448075eb0, buttonIndex=1) + 440 at WTAuthenticateBehavior.m:134
    frame #28: 0x000000010e4513ac Wingtip`-[MTBlockAlertView alertView:didDismissWithButtonIndex:](self=0x00007ff448075eb0, _cmd=0x00000001116a1fae, alertView=0x00007ff448075eb0, buttonIndex=1) + 108 at MTBlockAlertView.m:77
    frame #29: 0x0000000111436451 UIKit`-[UIAlertView modalItem:didDismissWithButtonIndex:] + 115
    frame #30: 0x00000001114eea63 UIKit`__87-[_UIModalItemsCoordinator _dismissItem:withTappedButtonIndex:animated:notifyDelegate:]_block_invoke237 + 120
    frame #31: 0x0000000111139d32 UIKit`__105-[_UIModalItemsPresentingViewController _dismissItem:andPresentItem:animated:completion:keepDimmingView:]_block_invoke256 + 651
    frame #32: 0x00000001110206e8 UIKit`-[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 299
    frame #33: 0x000000011100c68e UIKit`-[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 235
    frame #34: 0x000000011100c941 UIKit`-[UIViewAnimationState animationDidStop:finished:] + 78
    frame #35: 0x0000000110c62134 QuartzCore`CA::Layer::run_animation_callbacks(void*) + 310
    frame #36: 0x0000000112bed72d libdispatch.dylib`_dispatch_client_callout + 8
    frame #37: 0x0000000112bdd3fc libdispatch.dylib`_dispatch_main_queue_callback_4CF + 354
    frame #38: 0x00000001128a6289 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    frame #39: 0x00000001127f3854 CoreFoundation`__CFRunLoopRun + 1764
    frame #40: 0x00000001127f2d83 CoreFoundation`CFRunLoopRunSpecific + 467
    frame #41: 0x0000000113a0df04 GraphicsServices`GSEventRunModal + 161
    frame #42: 0x0000000110fc7e33 UIKit`UIApplicationMain + 1010
    frame #43: 0x000000010e1d1e02 Wingtip`main(argc=3, argv=0x00007fff51a2e4a0) + 370 at main.m:19
    frame #44: 0x0000000112e3d5c9 libdyld.dylib`start + 1
*thread#1:tid=0x38ee8e,0x0000000112f6551a libsystem_kernel.dylib`semaphore\u wait\u trap+10,queue='com.apple.main thread',stop reason=signal SIGSTOP
*帧0:0x0000000112f6551a libsystem_kernel.dylib`semaphore_wait_trap+10
帧#1:0x0000000112bde7b4 libdispatch.dylib`_dispatch_thread_semaphore_wait+16
帧#2:0x0000000112bdc3a2 libdispatch.dylib`_dispatch_barrier_sync_f_slow+321
帧#3:0x000000010fb08f92 CoreData`\u执行+114
帧#4:0x000000010fb0b7b8核心数据“-[NSManagedObjectContext(_NestedContextSupport)ManagedObjectContextDiUnregisterObjectsWithids:+72
帧#5:0x000000010fae0d2a CoreData`-[\u PFManagedObjectReferenceQueue\u processReferenceQueue:+1706
帧#6:0x000000010fb0ff33 CoreData`-[NSManagedObjectContext(_nInternalNotificationHandling)_processChangedStoreConfigurationNotification:+2771
帧#7:0x000000010fb71ee4核心数据“%uuuuu95-[NSManagedObjectContext(\u NSInternalNotificationHandling)\u发送或查询通知:选择器:]\u块\u调用+84
帧#8:0x000000010fb08c7b核心数据`developerSubmittedBlockToNSManagedObjectContextPerform+107
帧#9:0x000000010fb08bc4 CoreData`-[NSManagedObjectContext performBlockAndWait:+132
帧#10:0x000000010fb0f2f7核心数据“-[NSManagedObjectContext(\u NSInternalNotificationHandling)\u发送或查询:选择器:][231
帧#11:0x000000011289dd9c核心基金会``通知中心``正在向观察员发出呼叫`+12
帧#12:0x000000011280051d核心基础`\U CFX通知桩+2381
帧#13:0x000000011027e7fa Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:+68
帧#14:0x000000010fac06bc CoreData`-[NSPersistentStoreCoordinator(\u NSInternalMethods)\u PostStoresChangedNotification for Stores:changeKey:options:+220
帧#15:0x000000010fb0e5d6核心数据“-[NSPersistentStoreCoordinator removePersistentStore:错误:][278
帧#16:0x000000010e4bc430翼尖`uuu29-[TTPersistenceManager重置]\uBlock_invoke(.block_descriptor=)+528位于TTPersistenceManager.m:67
帧#17:0x000000010fb08c7b核心数据`developerSubmittedBlockToNSManagedObjectContextPerform+107
帧#18:0x000000010fb08bc4 CoreData`-[NSManagedObjectContext performBlockAndWait:+132
帧19:0x000000010e4bc17d翼尖“-[TTPersistenceManager重置](self=0x00007ff441604e50,_cmd=0x0000000118cfb867)+237位于TTPersistenceManager。m:59
帧#20:0x000000010e1dee19翼尖“-[WTGatekeeper resetPersistenceManager](self=0x00007ff44195a520,_cmd=0x000000010e8c079e)+121位于WTGatekeeper处。m:118
帧#21:0x000000011283df1c CoreFoundation`uuu调用uuu+140
帧#22:0x000000011283ddc4 CoreFoundation`-[NSInvocation invoke]+308
帧#23:0x000000010e48d141翼尖`-[TTStateMachine调用targetswithevent:state:](self=0x00007ff44177d2f0,_cmd=0x000000010e8e89a5,event=TTStateMachineEventDinter,state=0x000000010ea12f28)+977在TTStateMachine.m:277
帧#24:0x000000010e48aa59翼尖“-[TTStateMachine TransitionState:error:(TTStateMachine处的self=0x00007ff44177d2f0,_cmd=0x000000010e8c0919,state=0x000000010ea12f28,error=0x00007fff51a2d168)+521。m:105
帧#25:0x000000010e1e0a66翼尖“-[WTAuthenticationStateMachine TransitionState:error:(WTAuthenticationStateMachine处的self=0x00007ff44177d2f0,_cmd=0x000000010e8c0919,state=0x000000010ea12f28,error=0x00007fff51a2d168)+454。m:91
帧#26:0x000000010e48ac08翼尖“-[TTStateMachine TransitionState:(self=0x00007ff44177d2f0,_cmd=0x000000010e8c0746,state=0x000000010ea12f28)+168位于TTStateMachine。m:119
帧#27:0x000000010e1e3118翼尖`.[WTAuthenticateBehavior signOut]\u块调用(.block_描述符=,alertView=0x00007ff448075eb0,buttonIndex=1)+440位于WTAuthenticateBehavior。m:134
帧#28:0x000000010e4513ac翼尖“-[MTBlockAlertView-alertView:didDismissWithButtonIndex:](self=0x00007ff448075eb0,_cmd=0x0000000116A1FAE,alertView=0x00007ff448075eb0,buttonIndex=1)+108位于MTBlockAlertView.m:77
帧#29:0x0000000111436451 UIKit`-[UIAlertView模式项:didDismissWithButtonIndex:+115
帧#30:0x00000001114eea63 UIKit`uuuu87-[\uUIModalitemscoordinator\u dismission项:带点击按钮索引:动画:notifyDelegate:][u块调用237+120
帧#31:0x00000001111392 UIKit`uu 105-[uu UIModalItemsPresentingViewController u DismissionItem:和PresentEntItem:动画:完成:keepDimmingView:block\uInvoke256+651
帧#32:0x000000011110206E8 UIKit`-[UIViewAnimationBlockDelegate\u DiEndBlockAnimation:finished:context:+299
帧#33:0x000000011100c68e UIKit`-[UIViewAnimationState sendDelegateAnimationDidStop:finished:+235
帧#34:0x000000011100c941 UIKit`-[UIViewAnimationState animationDidStop:finished: