Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 68663b1

Browse files
authored
Merge pull request #412 from wordpress-mobile/fix/wpmediapickerviewcontroller-nsinternalinconsistencyexception-crash
Avoid `WPMediaPickerViewController` `performBatchUpdates` crash by wrapping the call in try-catch block
2 parents b66ddcd + aae7aa6 commit 68663b1

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ _None._
4848

4949
_None._
5050

51+
## 1.8.9
52+
53+
### Bug Fixes
54+
55+
- Fix WPMediaPickerViewController crash when performing batch updates [#412]
56+
5157
## 1.8.8
5258

5359
### Bug Fixes

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- WPMediaPicker (1.8.8)
2+
- WPMediaPicker (1.8.9-beta.1)
33

44
DEPENDENCIES:
55
- WPMediaPicker (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
WPMediaPicker: 0d40b8d66b6dfdaa2d6a41e3be51249ff5898775
12+
WPMediaPicker: 0ef7f4abcbff7ad20e271e7d09586e32924f5785
1313

1414
PODFILE CHECKSUM: 31590cb12765a73c9da27d6ea5b8b127c095d71d
1515

Pod/Classes/WPMediaPickerViewController.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,24 @@ - (void)registerDataSourceObservers {
134134
return;
135135
}
136136
if (incrementalChanges) {
137-
[weakSelf updateDataWithRemoved:removed inserted:inserted changed:changed moved:moves];
137+
/// Avoid NSInternalInconsistencyException crash by wrapping performBatchUpdates in the try catch block.
138+
///
139+
/// Apple documentation indicates if the collection view’s layout isn’t up to date before you call performBatchUpdates,
140+
/// additional reload may occur that can cause problems. Developers should update the data model inside the updates
141+
/// block or ensure the layout is updated before calling performBatchUpdates.
142+
/// However, MediaLibraryPickerDataSource reloads the data source before view controller gets informed about updates,
143+
/// creating a possibility for a crash.
144+
/// https://developer.apple.com/documentation/uikit/uicollectionview/1618045-performbatchupdates
145+
///
146+
/// Apple engineers reiterate this fact and point out the best way to avoid this issue is to adopt
147+
/// UICollectionViewDiffableDataSource which requires refactoring of the current solution
148+
/// https://developer.apple.com/forums/thread/728797?answerId=751887022#751887022
149+
150+
@try {
151+
[weakSelf updateDataWithRemoved:removed inserted:inserted changed:changed moved:moves];
152+
} @catch (NSException *exception) {
153+
[weakSelf.collectionView reloadData];
154+
}
138155
} else {
139156
[weakSelf.collectionView reloadData];
140157
}

WPMediaPicker.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'WPMediaPicker'
5-
s.version = '1.8.8'
5+
s.version = '1.8.9-beta.1'
66

77
s.summary = 'WPMediaPicker is an iOS controller that allows capture and picking of media assets.'
88
s.description = <<-DESC

0 commit comments

Comments
 (0)