From 07b5f8a48b6640b729f676baf5ea8462cea89122 Mon Sep 17 00:00:00 2001 From: Josh Heald Date: Wed, 22 Sep 2021 16:30:42 +0100 Subject: [PATCH] 371 Check conformance on call to optional method A rare crash found in WooCommerce iOS was caused by access to the `filename` of an asset, which is an optional member of the `WPMediaAsset` protocol. In WCiOS, this was not implemented, so the app crashed with `NSInvalidArgumentException -[WooCommerce.CancellableMedia filename]: unrecognized selector sent to instance` To prevent this, we check for `respondsToSelector:` before getting the filename, and default to using the creation date in the accessibility labels for documents when filename is not implemented. The fallback to creation date matches the existing approach taken for other media types. --- Pod/Classes/WPMediaCollectionViewCell.m | 6 +++++- WPMediaPicker.podspec | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/WPMediaCollectionViewCell.m b/Pod/Classes/WPMediaCollectionViewCell.m index 06cfae9..4e92549 100644 --- a/Pod/Classes/WPMediaCollectionViewCell.m +++ b/Pod/Classes/WPMediaCollectionViewCell.m @@ -210,7 +210,11 @@ - (void)configureAccessibility accessibilityLabel = [NSString stringWithFormat:NSLocalizedString(@"Audio, %@", @"Accessibility label for audio items in the media collection view. The parameter is the creation date of the audio."), formattedDate]; break; case WPMediaTypeOther: - accessibilityLabel = [NSString stringWithFormat:NSLocalizedString(@"Document: %@", @"Accessibility label for other media items in the media collection view. The parameter is the filename file."), [_asset filename]]; + if([_asset respondsToSelector:@selector(filename)]) { + accessibilityLabel = [NSString stringWithFormat:NSLocalizedString(@"Document: %@", @"Accessibility label for other media items in the media collection view. The parameter is the filename file."), [_asset filename]]; + } else { + accessibilityLabel = [NSString stringWithFormat:NSLocalizedString(@"Document, %@", @"Accessibility label for other media items in the media collection view. The parameter is the creation date of the document."), formattedDate]; + } break; default: break; diff --git a/WPMediaPicker.podspec b/WPMediaPicker.podspec index c590858..41ea56d 100644 --- a/WPMediaPicker.podspec +++ b/WPMediaPicker.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'WPMediaPicker' - s.version = '1.7.2' + s.version = '1.7.3-beta.1' s.summary = 'WPMediaPicker is an iOS controller that allows capture and picking of media assets.' s.description = <<-DESC