Main thread blocked after receiving objects restkit v0.20.3

人走茶凉 提交于 2019-12-23 05:49:04

问题


Once I pull data from server it gets saved in persistent store using Entity mapping.

Then I delete those objects manually.

Now when I try to pull the same data again i get the error saying Mapping HTTP response to nil target object... RKObjectmapperoperationfailed.

Main thread get's blocked may be there managed context in rest kit is not having object graph after deleting. I am not sure how to solve this error I tried resetting persistent store.

UPDATE

- (void)saveThreadedContext {
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter addObserver:self
                      selector:@selector(mergeThreadedContextChangesIntoMainContext:)
                      name:NSManagedObjectContextDidSaveNotification
                    object:self.threadedContext];

if ([[self threadedContext] hasChanges]) {

    NSError *error;

    BOOL contextDidSave = [[self threadedContext] save:&error];

    if (!contextDidSave) {

        // If the context failed to save, log out as many details as possible.
        NSLog(@"Failed to save to data store: %@", [error localizedDescription]);

        NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];

        if (detailedErrors != nil && [detailedErrors count] > 0) {

            for (NSError* detailedError in detailedErrors) {
                NSLog(@"  DetailedError: %@", [detailedError userInfo]);
            }
        } else {
            NSLog(@"  %@", [error userInfo]);
        }
    }
}

[defaultCenter removeObserver:self name:NSManagedObjectContextDidSaveNotification object:[self threadedContext]];
self.threadedContext = nil;
}

#pragma mark -
#pragma mark PrivateMethods
- (void)mergeThreadedContextChangesIntoMainContext:(NSNotification *)notification {
NSLog(@"%@:%@ merging changes", self, NSStringFromSelector(_cmd));
 NSManagedObjectContext * context = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).managedObjectContext;
[context     performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)     withObject:notification waitUntilDone:YES];
}

I use [self saveThreadedContext]; to save and merge thread context after deleting objects.

[context           performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) 
        withObject:notification waitUntilDone:YES];

holds lock on context which causes the block when restkit tries to merge it's context. wanted to know what type of concurrency to use while creating threadContext used to delete objects. i tried waitunitdone:NO and the block didn't arise again..need some explanation why

来源:https://stackoverflow.com/questions/18533984/main-thread-blocked-after-receiving-objects-restkit-v0-20-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!