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

Commit d0595d2

Browse files
committed
Merge branch 'release/0.7.0'
2 parents 9d5194c + 2216a4e commit d0595d2

9 files changed

+105
-36
lines changed

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 (0.6.1)
2+
- WPMediaPicker (0.7.0)
33

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

1111
SPEC CHECKSUMS:
12-
WPMediaPicker: 1596fcd29afc5a7d0c4baf9361a2b96887a2c3ad
12+
WPMediaPicker: f721cacd4113c6e718a1c7296083b9fd4a040536
1313

1414
COCOAPODS: 0.39.0

Pod/Classes/WPALAssetDataSource.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ - (ALAssetsLibrary *)assetsLibrary
9595
- (void)loadDataWithSuccess:(WPMediaChangesBlock)successBlock
9696
failure:(WPMediaFailureBlock)failureBlock
9797
{
98+
ALAuthorizationStatus authorizationStatus = ALAssetsLibrary.authorizationStatus;
99+
if (authorizationStatus == ALAuthorizationStatusDenied ||
100+
authorizationStatus == ALAuthorizationStatusRestricted) {
101+
if (failureBlock) {
102+
NSError *error = [NSError errorWithDomain:WPMediaPickerErrorDomain code:WPMediaErrorCodePermissionsFailed userInfo:nil];
103+
failureBlock(error);
104+
}
105+
return;
106+
}
98107
[self.extraAssets removeAllObjects];
99108
if (self.refreshGroups) {
100109
[self loadGroupsWithSuccess:^{
@@ -127,8 +136,14 @@ - (void)loadGroupsWithSuccess:(WPMediaChangesBlock)successBlock
127136
}
128137
} failureBlock:^(NSError *error) {
129138
NSLog(@"Error: %@", [error localizedDescription]);
139+
NSError * filteredError = error;
140+
if ([error.domain isEqualToString:ALAssetsLibraryErrorDomain] &&
141+
(error.code == ALAssetsLibraryAccessUserDeniedError || error.code == ALAssetsLibraryAccessGloballyDeniedError)
142+
) {
143+
filteredError = [NSError errorWithDomain:WPMediaPickerErrorDomain code:WPMediaErrorCodePermissionsFailed userInfo:error.userInfo];
144+
}
130145
if (failureBlock) {
131-
failureBlock(error);
146+
failureBlock(filteredError);
132147
}
133148
}];
134149
}

Pod/Classes/WPMediaCaptureCollectionViewCell.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,14 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification
107107
}
108108
}
109109

110+
- (BOOL)isAccessibilityElement
111+
{
112+
return YES;
113+
}
114+
115+
- (NSString *)accessibilityLabel
116+
{
117+
return NSLocalizedString(@"Camera", @"Accessibility label for the camera tile in the collection view");
118+
}
119+
110120
@end

Pod/Classes/WPMediaCollectionDataSource.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ typedef NS_ENUM(NSInteger, WPMediaType){
55
WPMediaTypeAll
66
};
77

8+
static NSString * const WPMediaPickerErrorDomain = @"WPMediaPickerErrorDomain";
9+
10+
typedef NS_ENUM(NSInteger, WPMediaPickerErrorCode){
11+
WPMediaErrorCodePermissionsFailed,
12+
WPMediaErrorCodePermissionsUnknow
13+
};
14+
815
@protocol WPMediaAsset;
916

1017
typedef void (^WPMediaChangesBlock)();

Pod/Classes/WPMediaCollectionViewCell.h

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

88
- (void)setCaption:(NSString *)caption;
99

10-
- (void)setImage:(UIImage *)image animated:(BOOL)animated;
10+
- (void)setImage:(UIImage *)image animated:(BOOL)animated withAccessibilityLabel:(NSString*)accessibilityLabel;
1111

1212
@end

Pod/Classes/WPMediaCollectionViewCell.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ - (void)prepareForReuse
4040
- (void)commonInit
4141
{
4242
_imageView = [[UIImageView alloc] init];
43+
_imageView.isAccessibilityElement = YES;
4344
_imageView.contentMode = UIViewContentModeScaleAspectFill;
4445
_imageView.clipsToBounds = YES;
4546
_imageView.backgroundColor = self.backgroundColor;
@@ -70,25 +71,28 @@ - (void)commonInit
7071
[self.contentView addSubview:_captionLabel];
7172
}
7273

73-
- (void)setImage:(UIImage *)image
74+
- (void)setImage:(UIImage *)image withAccessibilityLabel:(NSString*)accessibilityLabel
7475
{
75-
[self setImage:image animated:YES];
76+
[self setImage:image animated:YES withAccessibilityLabel:accessibilityLabel];
7677
}
7778

78-
- (void)setImage:(UIImage *)image animated:(BOOL)animated
79+
- (void)setImage:(UIImage *)image animated:(BOOL)animated withAccessibilityLabel:(NSString*)accessibilityLabel
7980
{
8081
if (!image){
8182
self.imageView.alpha = 0;
8283
self.imageView.image = nil;
84+
self.imageView.accessibilityLabel = nil;
8385
} else {
8486
if (animated) {
8587
[UIView animateWithDuration:0.3 animations:^{
8688
self.imageView.alpha = 1.0;
8789
self.imageView.image = image;
90+
self.imageView.accessibilityLabel = accessibilityLabel;
8891
}];
8992
} else {
9093
self.imageView.alpha = 1.0;
9194
self.imageView.image = image;
95+
self.imageView.accessibilityLabel = accessibilityLabel;
9296
}
9397
}
9498
}

Pod/Classes/WPMediaCollectionViewController.m

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#import "WPMediaCaptureCollectionViewCell.h"
44
#import "WPMediaPickerViewController.h"
55
#import "WPMediaGroupPickerViewController.h"
6-
#import "WPALAssetDataSource.h"
76

87
@import MobileCoreServices;
98
@import AVFoundation;
@@ -274,22 +273,21 @@ - (void)refreshData
274273
strongSelf.collectionView.allowsSelection = YES;
275274
strongSelf.collectionView.scrollEnabled = YES;
276275
[strongSelf.collectionView reloadData];
277-
if ([error.domain isEqualToString:ALAssetsLibraryErrorDomain]) {
278-
if (error.code == ALAssetsLibraryAccessUserDeniedError || error.code == ALAssetsLibraryAccessGloballyDeniedError) {
279-
NSString *otherButtonTitle = nil;
280-
if ([[self class] isiOS8OrAbove]) {
281-
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
282-
}
283-
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when access to the media library is not granted by the user")
284-
message:NSLocalizedString(@"This app needs permission to access your device media library in order to add photos and/or video to your posts. Please change the privacy settings if you wish to allow this.", @"Explaining to the user why the app needs access to the device media library.")
285-
delegate:self
286-
cancelButtonTitle:NSLocalizedString(@"OK", "")
287-
otherButtonTitles:otherButtonTitle,nil];
288-
alertView.tag = WPMediaCollectionAlertMediaLibraryPermissionsNeeded;
289-
alertView.delegate = strongSelf;
290-
[alertView show];
291-
return;
276+
if (error.domain == WPMediaPickerErrorDomain &&
277+
error.code == WPMediaErrorCodePermissionsFailed) {
278+
NSString *otherButtonTitle = nil;
279+
if ([[self class] isiOS8OrAbove]) {
280+
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
292281
}
282+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when access to the media library is not granted by the user")
283+
message:NSLocalizedString(@"This app needs permission to access your device media library in order to add photos and/or video to your posts. Please change the privacy settings if you wish to allow this.", @"Explaining to the user why the app needs access to the device media library.")
284+
delegate:self
285+
cancelButtonTitle:NSLocalizedString(@"OK", "")
286+
otherButtonTitles:otherButtonTitle,nil];
287+
alertView.tag = WPMediaCollectionAlertMediaLibraryPermissionsNeeded;
288+
alertView.delegate = strongSelf;
289+
[alertView show];
290+
return;
293291
}
294292
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when a generic error happened when loading media")
295293
message:NSLocalizedString(@"There was a problem when trying to access your media. Please try again later.", @"Explaining to the user there was an generic error accesing media.")
@@ -353,6 +351,24 @@ - (BOOL)isCaptureCellIndexPath:(NSIndexPath *)indexPath
353351
return asset;
354352
}
355353

354+
- (NSString *)accessibilityLabelForType:(WPMediaType)assetType atIndexPath:(NSInteger)index
355+
{
356+
NSString *accessibilityLabelFormat;
357+
switch (assetType) {
358+
case WPMediaTypeImage:
359+
accessibilityLabelFormat = NSLocalizedString(@"Asset %d, image.", @"Accessibility label for image thumbnails in the media collection view. The parameter is the index of the image in the collection view.");
360+
break;
361+
case WPMediaTypeVideo:
362+
accessibilityLabelFormat = NSLocalizedString(@"Asset %d, video", @"Accessibility label for video thumbnails in the media collection view. The parameter is the index of the video in the collection view.");
363+
break;
364+
default:
365+
accessibilityLabelFormat = NSLocalizedString(@"Asset %d", @"Accessibility label for asset (of unknown type) thumbnails in the media collection view. The parameter is the index of the asset in the collection view.");
366+
break;
367+
}
368+
369+
return [NSString stringWithFormat:accessibilityLabelFormat, index];
370+
}
371+
356372
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
357373
{
358374
if ([self isCaptureCellIndexPath:indexPath]) {
@@ -370,22 +386,29 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
370386
// Configure the cell
371387
__block WPMediaRequestID requestKey = 0;
372388
NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
389+
NSInteger itemIndex = indexPath.item + 1; // Asset position + 1 to avoid starting at "Asset 0"
390+
WPMediaType assetType = asset.assetType;
373391
requestKey = [asset imageWithSize:cell.frame.size completionHandler:^(UIImage *result, NSError *error) {
374392
BOOL animated = ([NSDate timeIntervalSinceReferenceDate] - timestamp) > 0.03;
375393
if (error) {
376394
cell.image = nil;
377395
NSLog(@"%@", [error localizedDescription]);
378396
return;
379397
}
380-
if ([NSThread isMainThread]){
398+
void (^setImage)() = ^{
381399
if (requestKey == cell.tag){
382-
[cell setImage:result animated:animated];
400+
NSString *accessibilityLabel = [self accessibilityLabelForType:assetType
401+
atIndexPath:itemIndex];
402+
[cell setImage:result
403+
animated:animated
404+
withAccessibilityLabel:accessibilityLabel];
383405
}
406+
};
407+
if ([NSThread isMainThread]){
408+
setImage();
384409
} else {
385410
dispatch_async(dispatch_get_main_queue(), ^{
386-
if (requestKey == cell.tag){
387-
[cell setImage:result animated:animated];
388-
}
411+
setImage();
389412
});
390413
}
391414
}];

Pod/Classes/WPPHAssetDataSource.m

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,24 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance
6969
- (void)loadDataWithSuccess:(WPMediaChangesBlock)successBlock
7070
failure:(WPMediaFailureBlock)failureBlock
7171
{
72-
if (self.refreshGroups) {
73-
[self loadGroupsWithSuccess:^{
74-
self.refreshGroups = NO;
72+
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
73+
if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusDenied ||
74+
[PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusRestricted) {
75+
if (failureBlock) {
76+
NSError *error = [NSError errorWithDomain:WPMediaPickerErrorDomain code:WPMediaErrorCodePermissionsFailed userInfo:nil];
77+
failureBlock(error);
78+
}
79+
return;
80+
}
81+
if (self.refreshGroups) {
82+
[self loadGroupsWithSuccess:^{
83+
self.refreshGroups = NO;
84+
[self loadAssetsWithSuccess:successBlock failure:failureBlock];
85+
} failure:failureBlock];
86+
} else {
7587
[self loadAssetsWithSuccess:successBlock failure:failureBlock];
76-
} failure:failureBlock];
77-
} else {
78-
[self loadAssetsWithSuccess:successBlock failure:failureBlock];
79-
}
88+
}
89+
}];
8090
}
8191

8292
- (void)loadGroupsWithSuccess:(WPMediaChangesBlock)successBlock

WPMediaPicker.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WPMediaPicker"
3-
s.version = "0.6.1"
3+
s.version = "0.7.0"
44
s.summary = "WPMediaPicker is an iOS controller that allows capture and picking of media assets."
55
s.description = <<-DESC
66
WPMediaPicker is an iOS controller that allows capture and picking of media assets.

0 commit comments

Comments
 (0)