I'm trying to present a UIImagePickerController from a UITableViewController subclass using the following code:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if(library)
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
else
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
[picker release];
If I create a brand new project and throw this code in, it works absolutely fine. However, in this project, for some reason, the UIImagePickerController's view appears as a blank white screen if I try to show the Photo Library, or shows the camera view but with no camera controls if I try to show the Camera.
Is there anything in a UITableViewController subclass that would be causing this? I get complaints about two-stage animations as well, but from what I've been able to find, this is an issue with Apple's code.
For some reason, changing the PRODUCT_NAME in the Info.plist (something which I was going to do anyway but hadn't gotten around to until just now) fixed this issue. I have absolutely no idea why, but I'm going to assume it was some obscure bug in the iPhone SDK.
Related
I implemented code for taking picture using AVCaptureSession. And i have button to pick image from Gallery. So, i need to use UIImagePickerController for picking image from gallery.
Is it possible to use UIImagepicker for picking Gallery and AVCaptureSession for taking picture. If i use this inside same app, appstore reject app or not?
Sure. You want to create your UIImagePickerController with a sourceType of UIImagePickerControllerSourceTypePhotoLibrary:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
I can't imagine that Apple would reject you for doing this in the same app that you're using AVCaptureSession - they're providing these classes to do exactly what you're proposing, after all.
I've finally nailed down a bug that crashes a UIImagePickerController when recording video. When the iPhone's VoiceOver accessibility setting is enabled, the recorder crashes without fail when calling presentModalViewController.
I've been unsuccessful so far in coming up with a workaround. Has anyone else experienced this and been able to fix it?
As #kamens mentioned in the comments above, a workaround is to include camera.showsCameraControls = NO in a completion block when presenting the modal view controller, like this:
[controller presentViewController:self animated:YES completion:^{self.showsCameraControls = NO;}];
However, with this solution, the camera controls flash momentarily as the camera is presented, then they disappear. Obviously not ideal when the controls really need to be hidden. The other workaround is to set camera.showsCameraControls = OFF... even less ideal.
#quellish, this is the output from the crash:
*** -[PLCameraToggleButton setAccessibilityValue:]: message sent to deallocated instance 0x4a330b0
#kamens, here is the code I'm using to set the mediaTypes and captureMode:
tmpCamera.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
tmpCamera.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
As #james mentions, this happens in iOS 5.1 when:
Using picker.showsCameraControls = NO
Using animated:NO in your call to [viewController presentViewController:picker animated:YES completion:nil];
The VoiceOver accessibility option is enabled.
...and, significantly, when only specifying movies as the media types accepted by picker:
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
However, I was able to fix this by changing the above mediaTypes line to:
picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
...which works fine given that the default camera controls are hidden and I can programmatically control whether to start recording a video or take a picture.
I don't claim to understand the cause of this crash.
In my application i have to upload a image and that image is taken from the ipad camera, now my query is when i choose the button "TakePicture" the cameraview opens can I resize the cameraview which captures the image.
Here is my code.
- (void) takePicture {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
Dont think so, that is an internal ui call,
You might be able to put some custom overlay on the camera view as quite a few other apps do, but to resize the internal camera view is not what apple wants us to do.
But then again, it would be a nice to have as we can use that for some really cool effects!
Do you mean view itself? No, the size couldn't be changed. If you mean size of taken/chosen image, user will be allowed to do resizing if you set allowsEditing to YES.
I want to make a camera application in which i want to start front camera automatically and capture image without user interaction. thanks in advance.
In addition to Robin's answer, add the following statements (before presentModalViewController:) to ensure that if the device has a front camera, that should be opened by default
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]){
self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; //skipping this was crashing my app with some ** Assertion failure.
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
Please note, if your app is compatible with devices running OS older than 4.0, you will have to put in conditional checks since cameraDevice property is available only in iOS 4.0 and later
The UIImagePickerController is a higher level abstraction to the camera. Have a look at AVFoundation examples to see how to get to the camera more directly.
The documentation for AVFoundation is here.
To do it while still using the picker, have a look at.1317978. Look around for some examples using UIGetScreenImage(). It used to be a private API but I think it is now allowed.
You might also want to look around at some examples concerning custom overlay, like this one.
I dont know how much you know about objective-c or iphone development. so I will tell how to take photos in your iphone app.
First you should get your self aquatinted with UIImagePickerController class
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
here is some examples for the same from apple
http://developer.apple.com/library/ios/samplecode/PhotoLocations/
http://developer.apple.com/library/ios/samplecode/PrintPhoto/
http://developer.apple.com/library/ios/samplecode/PhotoPicker/
http://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/
and next here is the code that will help you take the pics if you just place it in your .m file
- (void)selectPhotos
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
now get started.
I'm using UIImagePickerController to allow my user to select a video from the asset library.
When the UIImagePickerController is initially displayed, it shows thumbnails for the various movies that have been recorded.
Once the user selects a movie, it displays a "preview" view which allows them to playback and potentially edit the selected movie.
Is there any way to avoid displaying this view and instead return the movie that was selected on the thumbnail screen?
Here is the code I'm using:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
I haven't tested this myself, though I'll be attempting this in my own application shortly. If you take a look at the UIImagePickerController showsCameraControls documentation, it alludes to the fact that if you eliminate the camera controls you can take as many photos as you want.
So theoretically if you set showsCameraControls to NO, and assign your own cameraOverlayView UIView to let the user take a photo, you can dismiss the image picker without the preview view from showing.
Perhaps that helps. You could listen with the NSNotificationCenter on #"_UIImagePickerControllerUserDidCaptureItem". If the user select the item, you could dismiss the imagePicker and do your thumbnail stuff.
I had a similar issue, to remove an overlay on the preview view and could solve it with this approach.