Skip to content

Commit

Permalink
371 Check conformance on call to optional method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshheald committed Sep 22, 2021
1 parent 939737f commit 07b5f8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Pod/Classes/WPMediaCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion WPMediaPicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07b5f8a

Please sign in to comment.