2

I'm using this gist for FRC and UICollectionView. This was working fine till iOS 9.

Now, in iOS 10 sometimes my app crashes with SIGABRT signal crash at performBatchUpdates of collectionview. Even if the CollectionView escapes from crash it goes in coma with 1 or 2 cells.

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    // Checks if we should reload the collection view to fix a bug @ http://openradar.appspot.com/12954582
    if (self.shouldReloadCollectionView) {
        [self.collectionView reloadData];
    } else {
        [self.collectionView performBatchUpdates:^{ // CRASH : Thread 1: signal SIGABRT
            [self.blockOperation start];
        } completion:nil];
    }
}

Is this happening because of new upgraded functionality of UICollectionView? What's the fix?

vaibhav
  • 4,038
  • 1
  • 21
  • 51
iCanCode
  • 1,001
  • 1
  • 13
  • 24
  • For those who are fighting to figure out error in iOS 10, when using library/photos/media your app may be crashing with SIGABORT. You need to add some keys in Info.plist, check [this link.](http://stackoverflow.com/a/39631642/1223728) – Borzh Mar 31 '17 at 15:32

1 Answers1

1

After doing some research, found a fix for this. My app fetches data from a web server and inserts it using main thread.

I assumed that this signal is getting raised because of some kind of invalid data manipulation. As I doubted controllerDidChangeContent( main thread ) delegate is getting called as soon as the thread starts saving the data. [self.managedObjectContext save:&savingError];

This early invocation causes performBatchUpdates to indulge in data manipulation in the middle of the saving process which results in crash.

Putting the controllerDidChangeContent code inside dispatch_async fixed the crash and the coma state of CollectionView. I hope this helps someone.

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    dispatch_async(dispatch_get_main_queue(), ^{
        // Checks if we should reload the collection view to fix a bug @ http://openradar.appspot.com/12954582
        if (self.shouldReloadCollectionView) {
            [self.collectionView reloadData];
        } else {
            [self.collectionView performBatchUpdates:^{ // No crash :)
                [self.blockOperation start];
            } completion:nil];
        }
    }); 
}
iCanCode
  • 1,001
  • 1
  • 13
  • 24
  • Thank you for sharing your discoveries. I have similar problem in iOS10 and Swift 3. I already spent three weeks trying to discover what's going on and I'm getting crazy from it. Tried your fix didn't work for me neither. Obviously it is related to changes in CoreData. However I do all changes in background Context. Move all CoreData operations to main context doesn't help either. Maybe it has something to do with CoreData Context versioning. – Lweek Oct 26 '16 at 12:17