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
1 change: 1 addition & 0 deletions Example/WPMediaPicker/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ - (void) showPicker:(id) sender
mediaPicker.delegate = self;
mediaPicker.showMostRecentFirst = [self.options[MediaPickerOptionsShowMostRecentFirst] boolValue];
mediaPicker.allowCaptureOfMedia = [self.options[MediaPickerOptionsShowCameraCapture] boolValue];
mediaPicker.preferFrontCamera = [self.options[MediaPickerOptionsPreferFrontCamera] boolValue];
mediaPicker.allowMultipleSelection = [self.options[MediaPickerOptionsAllowMultipleSelection] boolValue];
mediaPicker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *ppc = mediaPicker.popoverPresentationController;
Expand Down
1 change: 1 addition & 0 deletions Example/WPMediaPicker/OptionsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

extern NSString const *MediaPickerOptionsShowMostRecentFirst;
extern NSString const *MediaPickerOptionsShowCameraCapture;
extern NSString const *MediaPickerOptionsPreferFrontCamera;
extern NSString const *MediaPickerOptionsAllowMultipleSelection;
extern NSString const *MediaPickerOptionsPostProcessingStep;

Expand Down
11 changes: 11 additions & 0 deletions Example/WPMediaPicker/OptionsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
NSString const *MediaPickerOptionsShowMostRecentFirst = @"MediaPickerOptionsShowMostRecentFirst";
NSString const *MediaPickerOptionsUsePhotosLibrary = @"MediaPickerOptionsUsePhotosLibrary";
NSString const *MediaPickerOptionsShowCameraCapture = @"MediaPickerOptionsShowCameraCapture";
NSString const *MediaPickerOptionsPreferFrontCamera = @"MediaPickerOptionsPreferFrontCamera";
NSString const *MediaPickerOptionsAllowMultipleSelection = @"MediaPickerOptionsAllowMultipleSelection";
NSString const *MediaPickerOptionsPostProcessingStep = @"MediaPickerOptionsPostProcessingStep";

typedef NS_ENUM(NSInteger, OptionsViewControllerCell){
OptionsViewControllerCellShowMostRecentFirst,
OptionsViewControllerCellShowCameraCapture,
OptionsViewControllerCellPreferFrontCamera,
OptionsViewControllerCellAllowMultipleSelection,
OptionsViewControllerCellPostProcessingStep,
OptionsViewControllerCellTotal
Expand All @@ -18,6 +20,7 @@ @interface OptionsViewController ()

@property (nonatomic, strong) UITableViewCell *showMostRecentFirstCell;
@property (nonatomic, strong) UITableViewCell *showCameraCaptureCell;
@property (nonatomic, strong) UITableViewCell *preferFrontCameraCell;
@property (nonatomic, strong) UITableViewCell *allowMultipleSelectionCell;
@property (nonatomic, strong) UITableViewCell *postProcessingStepCell;

Expand All @@ -43,6 +46,10 @@ - (void)viewDidLoad
self.showCameraCaptureCell.accessoryView = [[UISwitch alloc] init];
((UISwitch *)self.showCameraCaptureCell.accessoryView).on = [self.options[MediaPickerOptionsShowCameraCapture] boolValue];
self.showCameraCaptureCell.textLabel.text = @"Show Capture Cell";

self.preferFrontCameraCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
self.preferFrontCameraCell.accessoryView = [[UISwitch alloc] init];
self.preferFrontCameraCell.textLabel.text = @"Prefer Front Camera";

self.allowMultipleSelectionCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
self.allowMultipleSelectionCell.accessoryView = [[UISwitch alloc] init];
Expand Down Expand Up @@ -76,6 +83,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case OptionsViewControllerCellShowCameraCapture:
return self.showCameraCaptureCell;
break;
case OptionsViewControllerCellPreferFrontCamera:
return self.preferFrontCameraCell;
break;
case OptionsViewControllerCellAllowMultipleSelection:
return self.allowMultipleSelectionCell;
break;
Expand All @@ -95,6 +105,7 @@ - (void)done:(id) sender
NSDictionary *newOptions = @{
MediaPickerOptionsShowMostRecentFirst:@(((UISwitch *)self.showMostRecentFirstCell.accessoryView).on),
MediaPickerOptionsShowCameraCapture:@(((UISwitch *)self.showCameraCaptureCell.accessoryView).on),
MediaPickerOptionsPreferFrontCamera:@(((UISwitch *)self.preferFrontCameraCell.accessoryView).on),
MediaPickerOptionsAllowMultipleSelection:@(((UISwitch *)self.allowMultipleSelectionCell.accessoryView).on),
MediaPickerOptionsPostProcessingStep:@(((UISwitch *)self.postProcessingStepCell.accessoryView).on)
};
Expand Down
2 changes: 2 additions & 0 deletions Pod/Classes/WPMediaCapturePreviewCollectionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

@interface WPMediaCapturePreviewCollectionView : UICollectionReusableView

@property (nonatomic, assign) BOOL preferFrontCamera;

- (void)stopCaptureOnCompletion:(void (^)(void))block;
- (void)startCapture;

Expand Down
15 changes: 13 additions & 2 deletions Pod/Classes/WPMediaCapturePreviewCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ - (void)startCapture
self.session = [[AVCaptureSession alloc] init];
self.session.sessionPreset = AVCaptureSessionPreset1280x720;

AVCaptureDevice *device =
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *device = [self captureDevice];

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
Expand Down Expand Up @@ -123,4 +122,16 @@ - (NSString *)accessibilityLabel
return NSLocalizedString(@"Camera", @"Accessibility label for the camera tile in the collection view");
}

- (AVCaptureDevice *)captureDevice
{
if (self.preferFrontCamera) {
for (AVCaptureDevice *device in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
if (device.position == AVCaptureDevicePositionFront) {
return device;
}
}
}
return [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
}

@end
5 changes: 5 additions & 0 deletions Pod/Classes/WPMediaCollectionViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/
@property (nonatomic, assign) BOOL allowCaptureOfMedia;

/**
If the media picker allows media capturing, it will use the front camera by default when possible
*/
@property (nonatomic, assign) BOOL preferFrontCamera;

/**
If set the picker will show the most recent items on the top left. If not set it will show on the bottom right. Either way it will always scroll to the most recent item when showing the picker.
*/
Expand Down
12 changes: 12 additions & 0 deletions Pod/Classes/WPMediaCollectionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ - (instancetype)init
_layout = layout;
_selectedAssets = [[NSMutableArray alloc] init];
_allowCaptureOfMedia = YES;
_preferFrontCamera = NO;
_showMostRecentFirst = NO;
_filter = WPMediaTypeVideoOrImage;
_refreshGroupFirstTime = YES;
Expand Down Expand Up @@ -413,6 +414,7 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
UIGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showCapture)];
[self.captureCell addGestureRecognizer:tapGestureRecognizer];
}
self.captureCell.preferFrontCamera = self.preferFrontCamera;
[self.captureCell startCapture];
return self.captureCell;
}
Expand Down Expand Up @@ -571,12 +573,22 @@ - (void)showMediaCaptureViewController
imagePickerController.mediaTypes = [mediaTypes allObjects];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraDevice = [self cameraDevice];
imagePickerController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:imagePickerController animated:YES completion:^{

}];
}

- (UIImagePickerControllerCameraDevice)cameraDevice
{
if (self.preferFrontCamera && [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
return UIImagePickerControllerCameraDeviceFront;
} else {
return UIImagePickerControllerCameraDeviceRear;
}
}

- (void)captureMedia
{
NSString *mediaType = AVMediaTypeVideo;
Expand Down
5 changes: 5 additions & 0 deletions Pod/Classes/WPMediaPickerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
@property (nonatomic, assign) BOOL allowCaptureOfMedia;

/**
If the media picker allows media capturing, it will use the front camera by default when possible
*/
@property (nonatomic, assign) BOOL preferFrontCamera;

/**
If set the picker will allow the selection of multiple items. By default this value is YES.
*/
Expand Down
2 changes: 2 additions & 0 deletions Pod/Classes/WPMediaPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_allowCaptureOfMedia = YES;
_preferFrontCamera = NO;
_showMostRecentFirst = NO;
_allowMultipleSelection = YES;
_filter = WPMediaTypeVideoOrImage;
Expand All @@ -39,6 +40,7 @@ - (void)setupNavigationController
{
WPMediaCollectionViewController *vc = [[WPMediaCollectionViewController alloc] init];
vc.allowCaptureOfMedia = self.allowCaptureOfMedia;
vc.preferFrontCamera = self.preferFrontCamera;
vc.showMostRecentFirst = self.showMostRecentFirst;
vc.filter = self.filter;
vc.allowMultipleSelection = self.allowMultipleSelection;
Expand Down