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

Commit 05927b3

Browse files
committed
Merge branch 'hotfix/0.3.5'
2 parents 5ceed83 + ec17f79 commit 05927b3

File tree

4 files changed

+88
-16
lines changed

4 files changed

+88
-16
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.3.4)
2+
- WPMediaPicker (0.3.5)
33

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

1111
SPEC CHECKSUMS:
12-
WPMediaPicker: d1137b5447f1fb92cbed08742d8587b8c12c4d05
12+
WPMediaPicker: 53eb0bc7b04111a99f7be64ce873c12ff9600e7d
1313

1414
COCOAPODS: 0.37.1

Pod/Classes/WPMediaCaptureCollectionViewCell.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ - (void)dealloc
4848
- (void)stopCaptureOnCompletion:(void (^)(void))block
4949
{
5050
if (!self.session) {
51+
dispatch_async(dispatch_get_main_queue(), block);
5152
return;
5253
}
5354
self.captureVideoPreviewLayer.connection.enabled = NO;
@@ -61,7 +62,9 @@ - (void)stopCaptureOnCompletion:(void (^)(void))block
6162

6263
- (void)startCapture
6364
{
64-
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized && [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusNotDetermined) {
65+
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized &&
66+
[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusNotDetermined)
67+
{
6568
return;
6669
}
6770
dispatch_async(self.sessionQueue, ^{

Pod/Classes/WPMediaCollectionViewController.m

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@
88
@import MobileCoreServices;
99
@import AVFoundation;
1010

11-
@interface WPMediaCollectionViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate, WPMediaGroupPickerViewControllerDelegate, UIPopoverPresentationControllerDelegate>
11+
typedef NS_ENUM(NSUInteger, WPMediaCollectionAlert){
12+
WPMediaCollectionAlertMediaLibraryPermissionsNeeded,
13+
WPMediaCollectionAlertMediaCapturePermissionsNeeded
14+
};
15+
16+
@interface WPMediaCollectionViewController ()
17+
<
18+
UIImagePickerControllerDelegate,
19+
UINavigationControllerDelegate,
20+
WPMediaGroupPickerViewControllerDelegate,
21+
UIPopoverPresentationControllerDelegate,
22+
UIAlertViewDelegate
23+
>
1224

1325
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
1426
@property (nonatomic, strong) ALAssetsGroup *assetsGroup;
@@ -217,7 +229,25 @@ - (void)loadData
217229
}
218230
self.assetsGroup = group;
219231
} failureBlock:^(NSError *error) {
220-
NSLog(@"Error: %@", [error localizedDescription]);
232+
if ([error.domain isEqualToString:ALAssetsLibraryErrorDomain]) {
233+
if (error.code == ALAssetsLibraryAccessUserDeniedError || error.code == ALAssetsLibraryAccessGloballyDeniedError) {
234+
dispatch_async(dispatch_get_main_queue(), ^{
235+
NSString *otherButtonTitle = nil;
236+
if ([[self class] isiOS8OrAbove]) {
237+
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
238+
}
239+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when access to the media library is not granted by the user")
240+
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.")
241+
delegate:self
242+
cancelButtonTitle:NSLocalizedString(@"OK", "")
243+
otherButtonTitles:otherButtonTitle,nil];
244+
alertView.tag = WPMediaCollectionAlertMediaLibraryPermissionsNeeded;
245+
alertView.delegate = self;
246+
[alertView show];
247+
});
248+
249+
}
250+
}
221251
}];
222252
return;
223253
}
@@ -485,11 +515,7 @@ - (void)captureMedia
485515
dispatch_async(dispatch_get_main_queue(), ^{
486516
if (!granted)
487517
{
488-
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Capture", @"Title for alert when access to media capture is not granted")
489-
message:NSLocalizedString(@"This app needs permission to access the Camera to capture new media, please change the privacy settings if you wish to allow this.", @"")
490-
delegate:self
491-
cancelButtonTitle:NSLocalizedString(@"OK", nil)
492-
otherButtonTitles:nil] show];
518+
[self showAlertAboutMediaCapturePermission];
493519
return;
494520
}
495521
[self showMediaCaptureViewController];
@@ -499,14 +525,26 @@ - (void)captureMedia
499525
}
500526

501527
dispatch_async(dispatch_get_main_queue(), ^{
502-
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Capture", @"Title for alert when access to media capture is not granted")
503-
message:NSLocalizedString(@"This app needs permission to access the Camera to capture new media, please change the privacy settings if you wish to allow this.", @"")
504-
delegate:self
505-
cancelButtonTitle:NSLocalizedString(@"OK", nil)
506-
otherButtonTitles:nil] show];
528+
[self showAlertAboutMediaCapturePermission];
507529
});
508530
}
509531

532+
- (void)showAlertAboutMediaCapturePermission
533+
{
534+
NSString *otherButtonTitle = nil;
535+
if ([[self class] isiOS8OrAbove]) {
536+
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
537+
}
538+
539+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Capture", @"Title for alert when access to media capture is not granted")
540+
message:NSLocalizedString(@"This app needs permission to access the Camera to capture new media, please change the privacy settings if you wish to allow this.", @"")
541+
delegate:self
542+
cancelButtonTitle:NSLocalizedString(@"OK", nil)
543+
otherButtonTitles:otherButtonTitle, nil];
544+
alertView.tag = WPMediaCollectionAlertMediaCapturePermissionsNeeded;
545+
[alertView show];
546+
}
547+
510548
- (void)processMediaCaptured:(NSDictionary *)info
511549
{
512550
self.ignoreMediaNotifications = YES;
@@ -618,4 +656,35 @@ - (void)mediaGroupPickerViewControllerDidCancel:(WPMediaGroupPickerViewControlle
618656
[self dismissViewControllerAnimated:YES completion:nil];
619657
}
620658
}
659+
660+
#pragma mark - UIAlertViewDelegate
661+
662+
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
663+
switch (alertView.tag) {
664+
case WPMediaCollectionAlertMediaLibraryPermissionsNeeded:
665+
{
666+
if (alertView.cancelButtonIndex == buttonIndex){
667+
if ([self.picker.delegate respondsToSelector:@selector(mediaPickerControllerDidCancel:)]) {
668+
[self.picker.delegate mediaPickerControllerDidCancel:self.picker];
669+
}
670+
} else if (alertView.firstOtherButtonIndex == buttonIndex) {
671+
if ([self.picker.delegate respondsToSelector:@selector(mediaPickerControllerDidCancel:)]) {
672+
[self.picker.delegate mediaPickerControllerDidCancel:self.picker];
673+
}
674+
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
675+
[[UIApplication sharedApplication] openURL:settingsURL];
676+
}
677+
} break;
678+
case WPMediaCollectionAlertMediaCapturePermissionsNeeded:
679+
{
680+
if (alertView.firstOtherButtonIndex == buttonIndex) {
681+
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
682+
[[UIApplication sharedApplication] openURL:settingsURL];
683+
}
684+
} break;
685+
default:
686+
break;
687+
}
688+
}
689+
621690
@end

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.3.4"
3+
s.version = "0.3.5"
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)