iPhone video recording: "cameraCaptureMode 1 not available because mediaTypes does contain public.movie" - objective-c

I tried to record a video.
The message I got is from the following code on the device:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
Any ideas? I think it should be really easy to take a video. When I start the "Camera" app of the phone I have the choice between video and picture. Shouldn't it be available for my app also?

The problem was the way I was trying to set the mode to video mode.
Instead of using this:
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
I changed it to this:
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
and it worked.

For Swift 3.0, you have to add below line to support both photo and video
import MobileCoreServices
imagePicker.mediaTypes = [kUTTypeMovie as String, kUTTypeImage as String]

Add to above answers, as Micko mentioned, you need to add MobileCoreServices.framework in your project and ref it in your imagePickerController.
For those who want to have a switch under the toolbar in your image shooting view, just set the mediaTypes delegate as follows:
imagePC.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
Now, you can have both still image taking and video taking, enjoy!!!

Xcode 9 - Swift 4.x:
Take care about the order of these statements:
imagePickerController.mediaTypes = [kUTTypeMovie as String]
imagePickerController.cameraCaptureMode = .video
And you remember to add to info.plist:

And if you are working with Swift, then you will have to add MobileCoreServices.framework as well as the following Module where you are trying to record the video!
import MobileCoreServices
Then overall your code will something like this
var imag = UIImagePickerController()
imag.delegate = self
imag.sourceType = UIImagePickerControllerSourceType.Camera;
imag.cameraDevice = UIImagePickerControllerCameraDevice.Rear //or Front
imag.mediaTypes = [kUTTypeMovie];
self.presentViewController(imag, animated: true, completion: nil)

This method will opens the library of videos in my ipod 4.Not the video camera of my device.
Will someone tell me how to sort out from the problem ,I have tried the both ways described above.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
and
imagePickerController.mediaTypes =
[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
Thanks for your help.

enter code herePlease try this,this will opens the video camera
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *tmp_picker=[[UIImagePickerController alloc]init];
tmp_picker.sourceType=UIImagePickerControllerSourceTypeCamera;
tmp_picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
tmp_picker.delegate=self;
[self presentModalViewController:tmp_picker animated:YES];
[tmp_picker release];
NSLog(#"button index is %i",buttonIndex);
}

Related

iOS 8 UIActivityViewController and/or UIPopoverController are not dissmissed when clicked outside of them

I have read the UIPopoverController docs and more then 10 stackoverflow solutions which none work in iOS 8.0.2 ipad device.
THE GOAL:
I want to present a sharing view which when clicked outside dissmisses.
THE PROBLEM:
The code works fine below iOS 8.0.
THE CODE (tried many versions...):
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
self.act = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.act presentPopoverFromRect:CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2, self.view.bounds.size.width/2, self.view.bounds.size.width/2) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
self.act.delegate = self;
I have added the :
UIPopoverControllerDelegate
WHAT I HAVE TRIED:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
As soon that the
UIPopoverController
is presented the view losses focus and doesn't register touches. Therefore, I can't handle touches outside the self.act rect space in order to force a dissmisal.
also...
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
UIPopoverPresentationController *presentationController = [activityViewController popoverPresentationController];
presentationController.sourceView = self.view; // if button or change to self.view.
[self.parentViewController presentViewController:activityViewController animated:YES completion:nil];
and I tried to present the UIActivityViewController and UIPopoverController from the parent which didn't work aswell.
Please help, I lost half day on something this stupid which works on iOS 7.1 and not on iOS 8+ which is ridiculous and I still have no clue why.
I will try to add the cancel button which has also disappeared in iOS8+.
UPDATE 1:
Adding a UIButton inside a UIBarButtonItem didn't help...
UIButton *control = (UIButton *) sender;
[control setFrame:CGRectMake(300, 300, 100, 100)];
[control setBackgroundColor:[UIColor redColor]];
UIBarButtonItem *barButtonItemView = [[UIBarButtonItem alloc] init];
[barButtonItemView setCustomView:control];
[self.popup presentPopoverFromBarButtonItem:barButtonItemView permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
UPDATE 2 - 19.12.2014. (iOS 7.1. - 8.1.2):
The accepted answer works on iOS 8.1. I had some errors with iOS 7.1. so I modified it to work for iOS 7.1. I have stated on which devices the code works in the comments below the answer.
// publish - sharing
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
NSLog(#" SHARING - 1 - ");
[self presentViewController:activityViewController animated:YES completion:^{}];
}
else
{
// Change Rect to position Popover
NSLog(#" SHARING - 2 - ");
self.popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width * 3 / 5 ,
self.view.frame.size.width/2,
self.view.frame.size.width/10,
self.view.frame.size.width/10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
How about just add this.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
activityViewController.popoverPresentationController.sourceView = self.view;

How to Skip Retake/Use Photo option after capturing image by camera in IOS 7

Here I am developing an app using IOS 7 in which camera used to capture the image. but after capturing image it displaying Retake/Use Photo options. i want that after capturing image it directly go to next screen without showing default Retake?use Photo Options.I google out this Issue but I don't get proper solution. Please help me to solve this issue.
Thanks in advance.
Here is the code snippet that i am using in my project
-(void)StartCamera
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Device has no camera" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[myAlertView show];
}
else
{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
}
The stock UIImagePickerControllerSourceTypeCamera provided by iOS has both these buttons.
One way to achieve what you want is to continue to use UIImagePickerViewController and set showsCameraControls to NO. Then, provide your own user interface using cameraOverlayView for your custom overlay view.
self.picker.showsCameraControls = NO;
self.overlay = [[OverlayViewController alloc] initWithNibName:#"Overlay" bundle:nil];
self.overlay.pickerReference = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
self.picker.delegate = self.overlay;
Another way is to use AVFoundation to create your own camera view.
let picker = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = false
picker.automaticallyAdjustsScrollViewInsets = true
picker.sourceType = UIImagePickerControllerSourceType.camera
For both Camera as well as gallery.
If you're using any third party library for editing it will directly guide you to that library or dismiss the picker controller without giving preview.

iOS 7 - Black preview screen in UIImagePickerController

Using the below code to launch the image picker to capture the image. Can any one help out to close this issue...
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if (self.camera)
{
self.camera = nil;
}
self.camera = [[UIImagePickerController alloc] init];
self.camera.sourceType = UIImagePickerControllerSourceTypeCamera;
self.camera.allowsEditing = NO;
self.camera.delegate = self;
[self presentViewController:self.camera animated:YES completion:NULL];
}
Before launching the UIImagePickerController if you have any GCD in background might be a reason for this issue. In my code have GCD before launching the UIImagePickerController, now removed the GCD it's working fine.

UIImagepickerController is not showing camera in full view for iPhone 4.2

When I invoke camera using the UIimagepicker controller it does not show in full screen mode on iPhone with iOS version 4.2, but it does work in iOS 5.
Can anyone tell me the code that needs to be changed and what is the problem with existing code?
I am using the following code:
- (IBAction)takePicture:(id)sender
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.allowsEditing = NO;
imagePicker.toolbarHidden = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
imagePicker.wantsFullScreenLayout = YES;
if ([UIImagePickerController respondsToSelector:#selector(isCameraDeviceAvailable:)])
{
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
[imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
}
}
// Show the camera UI and View Finder.
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
Please check the attachment
Image is here
one of the solution is applying scaling trasnformation - here on stack maybe it will help
I don't see why you are doing these 3 things:
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.camPicker.view setUserInteractionEnabled:YES];
Or for that matter why you are caching the instance of UIImagePickerController (this may cause significantly higher idle memory usage for your application compared to discarding the image picker controller between uses).
Does it work better if you don't do these things?

presentModalViewController in UISplitViewControllers detailView not presenting the view in full screen

I have added the UISplitViewController view in my mainViewControllers view, the code is below.
documentsRootViewController = [[DocumentsRootViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:documentsRootViewController];
documentsRootViewController.title = #"Document List";
documentDetailView = [[DocumentsDetailView alloc] initWithNibName:#"DocumentsDetailView" bundle:nil];
documentsRootViewController.detailViewController = documentDetailView;
docSplitViewController = [[UISplitViewController alloc] init];
docSplitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, documentDetailView, nil];
docSplitViewController.delegate = documentDetailView;
CGRect splitViewFrame = CGRectMake(0, 0, cetralArea.frame.size.width, cetralArea.frame.size.height);
docSplitViewController.view.frame = splitViewFrame;
[cetralArea addSubview:docSplitViewController.view];
now what I want is to present a ViewController from the DetailView of the UISplitViewController I am trying to do it as below inside the DetailViewControllers Click Me! buttons click.
- (IBAction) buttonClicked:(id)sender
{
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:#"pdf" inDirectory:nil];
NSString *filePath = [pdfs lastObject]; assert(filePath != nil); // Path to last PDF file
ReaderDocument *readerDocument = [ReaderDocument withDocumentFilePath:filePath password:phrase];
if (readerDocument != nil) // Must have a valid ReaderDocument object in order to proceed with things
{
ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];
rViewController.delegate = self; // Set the ReaderViewController delegate to self
[self presentModalViewController:rViewController animated:NO];
}
}
but this is resulting in an awkward presentation
can anyone suggest what is the problem here, thanks in advance..
In your screenshots I can't really tell where is your split view controller left side and right side (detail view) located. Change background colors of the views to distinguish positions. Seems you are having problems with them.
Anyways, you can try presenting the modal view controller from the splitView instead of the Detail.
[splitViewController presentModalViewController:rViewController animated:NO];
I believe the trick here is changing the modalPresentationStyle (and optionally modalTransitionStyle) of the view controller that you want to display modally:
ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];
rViewController.delegate = self; // Set the ReaderViewController delegate to self
rViewController.modalPresentationStyle = UIModalPresentationFullScreen;
rViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:rViewController animated:YES completion:nil];
I had the same problem (in iOS 5.1). Set the modalPresentationStyle to UIModalPresentationPageSheet and it should work as expected.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
rViewController.modalPresentationStyle = UIModalPresentationPageSheet;
rViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
What i found is you are giving splitview size like cetralArea.frame.size.width.
Instead of that simply give directly size that you want to give to the Splitview.
Hope it will work for you.