Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Pod/Classes/WPALAssetDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ - (ALAssetsLibrary *)assetsLibrary
- (void)loadDataWithSuccess:(WPMediaChangesBlock)successBlock
failure:(WPMediaFailureBlock)failureBlock
{
ALAuthorizationStatus authorizationStatus = ALAssetsLibrary.authorizationStatus;
if (authorizationStatus == ALAuthorizationStatusDenied ||
authorizationStatus == ALAuthorizationStatusRestricted) {
if (failureBlock) {
NSError *error = [NSError errorWithDomain:WPMediaPickerErrorDomain code:WPMediaErrorCodePermissionsFailed userInfo:nil];
failureBlock(error);
}
return;
}
[self.extraAssets removeAllObjects];
if (self.refreshGroups) {
[self loadGroupsWithSuccess:^{
Expand Down Expand Up @@ -127,8 +136,14 @@ - (void)loadGroupsWithSuccess:(WPMediaChangesBlock)successBlock
}
} failureBlock:^(NSError *error) {
NSLog(@"Error: %@", [error localizedDescription]);
NSError * filteredError = error;
if ([error.domain isEqualToString:ALAssetsLibraryErrorDomain] &&
(error.code == ALAssetsLibraryAccessUserDeniedError || error.code == ALAssetsLibraryAccessGloballyDeniedError)
) {
filteredError = [NSError errorWithDomain:WPMediaPickerErrorDomain code:WPMediaErrorCodePermissionsFailed userInfo:error.userInfo];
}
if (failureBlock) {
failureBlock(error);
failureBlock(filteredError);
}
}];
}
Expand Down
7 changes: 7 additions & 0 deletions Pod/Classes/WPMediaCollectionDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ typedef NS_ENUM(NSInteger, WPMediaType){
WPMediaTypeAll
};

static NSString * const WPMediaPickerErrorDomain = @"WPMediaPickerErrorDomain";

typedef NS_ENUM(NSInteger, WPMediaPickerErrorCode){
WPMediaErrorCodePermissionsFailed,
WPMediaErrorCodePermissionsUnknow
};

@protocol WPMediaAsset;

typedef void (^WPMediaChangesBlock)();
Expand Down
30 changes: 14 additions & 16 deletions Pod/Classes/WPMediaCollectionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import "WPMediaCaptureCollectionViewCell.h"
#import "WPMediaPickerViewController.h"
#import "WPMediaGroupPickerViewController.h"
#import "WPALAssetDataSource.h"

@import MobileCoreServices;
@import AVFoundation;
Expand Down Expand Up @@ -274,22 +273,21 @@ - (void)refreshData
strongSelf.collectionView.allowsSelection = YES;
strongSelf.collectionView.scrollEnabled = YES;
[strongSelf.collectionView reloadData];
if ([error.domain isEqualToString:ALAssetsLibraryErrorDomain]) {
if (error.code == ALAssetsLibraryAccessUserDeniedError || error.code == ALAssetsLibraryAccessGloballyDeniedError) {
NSString *otherButtonTitle = nil;
if ([[self class] isiOS8OrAbove]) {
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when access to the media library is not granted by the user")
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.")
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", "")
otherButtonTitles:otherButtonTitle,nil];
alertView.tag = WPMediaCollectionAlertMediaLibraryPermissionsNeeded;
alertView.delegate = strongSelf;
[alertView show];
return;
if (error.domain == WPMediaPickerErrorDomain &&
error.code == WPMediaErrorCodePermissionsFailed) {
NSString *otherButtonTitle = nil;
if ([[self class] isiOS8OrAbove]) {
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when access to the media library is not granted by the user")
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.")
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", "")
otherButtonTitles:otherButtonTitle,nil];
alertView.tag = WPMediaCollectionAlertMediaLibraryPermissionsNeeded;
alertView.delegate = strongSelf;
[alertView show];
return;
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when a generic error happened when loading media")
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.")
Expand Down
24 changes: 17 additions & 7 deletions Pod/Classes/WPPHAssetDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,24 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance
- (void)loadDataWithSuccess:(WPMediaChangesBlock)successBlock
failure:(WPMediaFailureBlock)failureBlock
{
if (self.refreshGroups) {
[self loadGroupsWithSuccess:^{
self.refreshGroups = NO;
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusDenied ||
[PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusRestricted) {
if (failureBlock) {
NSError *error = [NSError errorWithDomain:WPMediaPickerErrorDomain code:WPMediaErrorCodePermissionsFailed userInfo:nil];
failureBlock(error);
}
return;
}
if (self.refreshGroups) {
[self loadGroupsWithSuccess:^{
self.refreshGroups = NO;
[self loadAssetsWithSuccess:successBlock failure:failureBlock];
} failure:failureBlock];
} else {
[self loadAssetsWithSuccess:successBlock failure:failureBlock];
} failure:failureBlock];
} else {
[self loadAssetsWithSuccess:successBlock failure:failureBlock];
}
}
}];
}

- (void)loadGroupsWithSuccess:(WPMediaChangesBlock)successBlock
Expand Down