From 25f34ad7e8f9b24381870954d59d82a4b23004e9 Mon Sep 17 00:00:00 2001 From: chrisga Date: Tue, 20 Sep 2016 19:08:55 -0700 Subject: [PATCH] Crash with deleted photos in iTunes library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When syncing down deleted images from an iPhoto library, it crashes because the path doesn’t exist anymore. --- QBImagePicker/QBAssetsViewController.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/QBImagePicker/QBAssetsViewController.m b/QBImagePicker/QBAssetsViewController.m index 37381715..6bcfb36e 100644 --- a/QBImagePicker/QBAssetsViewController.m +++ b/QBImagePicker/QBAssetsViewController.m @@ -407,8 +407,11 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance NSIndexSet *changedIndexes = [collectionChanges changedIndexes]; if ([changedIndexes count]) { - [self.collectionView reloadItemsAtIndexPaths:[changedIndexes qb_indexPathsFromIndexesWithSection:0]]; - } + // We need to remove the removed images, since reloading them will cause a crash + // "uncaught ObjC exception, reason: attempt to delete and reload the same index path" + NSMutableIndexSet *changedWithoutRemovalsIndexes = [changedIndexes mutableCopy]; + [changedWithoutRemovalsIndexes removeIndexes:removedIndexes]; + [self.collectionView reloadItemsAtIndexPaths:[changedWithoutRemovalsIndexes qb_indexPathsFromIndexesWithSection:0]]; } completion:NULL]; }