UIImagePickerController allowsEditing=YES just for video - ios

I am using the UIImagePickerController to let the user select a photo or video. The problem I am facing, is I use my own image editor for photo's so want allowsEditing=NO for photo's, but video must be a certain length so I want allowsEditing=YES for video.
Setting videoMaximumDuration for the image picker works fine when recording video, but if selecting from the camera roll it only informs the user that the video is too long if allowsEditing is enabled.
So far, I can successfully change the allowsEditing property when using the camera by listening for the ImageControlModeChanged notification. Then I can change the property using:
- (void)imageCaptured:(NSNotification *)notification
{
if (imagePicker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo) {
imagePicker.allowsEditing = YES;
} else {
imagePicker.allowsEditing = NO;
}
}
However this doesn't work when selecting from the Camera roll. I have monitored the notifications and can't see one that would be useful to change the allowsEditing property depending on which item was selected.
Is this even possible?
Thanks

Why not creating 2 or even 4 UIImagePickerControllers instead of messing around with notifications?
- (void) useCamera
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void) useCameraRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)videoRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = YES;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)vidCam
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
Edit:
After better understanding of the question I don't think it's possible. There are a few notification you can use but those are not documented anywhere or working on iOS7. If that is really the case the best solution I can think of is to use a 3rd party such as github.com/andrei200287/SAVideoRangeSlider and allowsEditing = NO for everything.

Simply allow editing on both image and video pick, but in didFinishPicking delegate method, for photo, choose original photo and not edited photo. However picker will still show that square box over image.

Try this
assign properties in view did load , not in imageCaptured method. it works fine
videoController.delegate = self;
videoController.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
videoController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoController.sourceType];
videoController.allowsEditing = YES;

Related

How to limit video crop section for 10 seconds in iOS?

I want to set the cropping section set to 10 seconds time. Is it possible to do with default image picker. Is it is how may I do it?
Try This code..
-(void)recordVideo{
imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *) kUTTypeMovie, (NSString *) kUTTypeMPEG4, nil];
imagePicker.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;
[imagePicker setVideoMaximumDuration:10.0f];
sourceType = [UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
if (![sourceType containsObject:(NSString *) kUTTypeMovie]) {
NSLog(#"Can not Save Video");
}
[self presentModalViewController:imagePicker animated:YES];
}
Make sure that, you have to set allowsEditing to YES before presenting the controller.

Camera show black screen in ios 8

This code for capturing image one by one from camera,but after taking one image next time camera will open but with black screen(like it,s shutter close).all other ios version its working,but not working in ios 8.please tell me how can i solve it?
-(void)openCamera
{
if(![PickerHandler doesDeviceSupportMediaType:ITEM_TYPE_PHOTO])
{
[PickerHandler showNoDeviceSupportWarningForMediaType:ITEM_TYPE_PHOTO withDelegate:self];
}
else
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
[self presentViewController:picker animated:YES completion:nil];
}
}
Go to Settings > Privacy > Pictures ... and check if your app have permission.
In the code, use this to verify camera access.
- (BOOL)authorizedCameraAccess
{
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
return (status == AVAuthorizationStatusAuthorized);
}
this code is not work in simulator.
UIImagePickerController *videoScreen = [[UIImagePickerController alloc] init];
videoScreen.sourceType = UIImagePickerControllerSourceTypeCamera;
videoScreen.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
videoScreen.allowsEditing = NO;
videoScreen.delegate = self;
[self presentViewController:videoScreen animated: YES completion:NO];
Implement This method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:NO completion:NO];
}

UIImagePickerController with UIImagePickerControllerSourceTypeCamera crash EXC_BAD_ACCESS in ios7

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
This code make crash EXC_BAD_ACCESS on ios7 devices.
On iOS6 - all okay, and UIImagePickerControllerSourceTypePhotoLibrary work normal.
To work with camera
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
(NSString *) kUTTypeMovie, nil];
[self presentViewController:imagePickerController animated:YES completion:nil]; }

Display the Saved Video in iPad

I want to display the saved videos in Photo Library in popOver controller just like images.
How can i show the videos in popOver controller?
My code for Images is as follow:
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
[popoverController release];
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:CGRectMake(100, 100, 150, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[imagePicker release];
Help me to solve this problem.
Thank you,
You have to choose right mediaType:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
//here
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
imagePicker.delegate = self;

Use the UIImagePickerController on a iphone simulator

I have the method, that take photos from gallery or from the camera
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
But when i run it on the simulator, code doesnt work. And it doesnt work in picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum and picker.sourceType = UIImagePickerControllerSourceTypeCamera
Is the problem in the simulator or in the code?
Try this,
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self.navigationController presentModalViewController:picker animated:NO];
If you are creating the app for iPad. You will have to present the gallery in a popOver control.
Swift 3/4/5 verison:
if UIImagePickerController.isSourceTypeAvailable(.camera) {
picker.sourceType = .camera
}
else {
picker.sourceType = .savedPhotosAlbum // or .photoLibrary
}
Swift 2 version:
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
picker.sourceType = .Camera
}
else {
picker.sourceType = .SavedPhotosAlbum // or .PhotoLibrary
}
In simulator, you can't use cameraCaptureMode and showsCameraControls.
In simulator your picker.sourceType = UIImagePickerControllerSourceTypeCamera wont be called as there is no camera available in simulator. Also its a good practice to check whether the source type is available to avoid crashes.
#import <MobileCoreServices/UTCoreTypes.h>
….
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
imagePickerCamera.delegate = self;
imagePickerCamera.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePickerCamera.allowsEditing = YES;
imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePickerCamera animated:YES completion:nil];
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePickerAlbum =[[UIImagePickerController alloc] init];
imagePickerAlbum.delegate = self;
imagePickerAlbum.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePickerAlbum.allowsEditing = YES;
imagePickerAlbum.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerAlbum animated:YES completion:nil];
}
Similarly to the above answers, but I found this easier. Show a pop up alert if the device doesn't have a camera (like the simulator). Sam code, different usage:
//button if to take a photo
- (IBAction)takePhoto:(id)sender {
//checks if device has a camera
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"You don't have a camera for this device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
//shows above alert if there's no camera
[noCameraAlert show];
}
//otherwise, show a modal for taking a photo
else {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:NULL];
}
}

Resources