Starting an iPhone app in camera mode shows just a blank screen - iphone

I'm creating an app for the iPhone which is supposed to start in camera mode (with a custom layout on top but that comes later). I've already created a version of this app where I press a button, that allows me to either choose a photo from the iPhone album or take a new photo.
Trying to use the same code in a different fails.
Originally I had a function 'takePicture' which I used to start the camera
- (void)takePicture
{
isInCaptureMode = YES;
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
imagePicker.videoQuality = UIImagePickerControllerQualityTypeMedium;
// set delegate
[imagePicker setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
So I thought to myself "I can probably create a single view app, throw this code into the view controller's viewDidLoad function and use that as a starting point". But alas, I've been stuck there. When I do that the application starts and (if the device has a camera) the screen goes blackish blank, if the device does not have a camera (iPad or the simulator) the app crashes.
I originally created the app using Xcode 3 but have now migrated over to 4.2 the original app runs fine in 4.2 though (after I did a little bit of tweaking)
Can anyone explain why this happens?

can you try the following code to see what happen?
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
//you can get picture from Library is there is no camera
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];

So, like I said in the comment. As soon as I called the code from 'viewDidAppear' instead of 'viewDidLoad' it finally ran...

Related

Camera Filters in ios7

How I can use the camera filters that already exist in iOS7?
If i used this code:
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
the camera will open, and I can capture a photo but without using the filters.
my question is: can I use the exist filters in camera view in iOS7?
You should be able to use CIFilters. More info about CIFilters can be found here. Or you could use the awesome framework that's called GPUImage.

Why does UIImagePickerControllerSourceTypePhotoLibrary not let the user pick an album?

I am currently developing an iPad application for iPad, where I use a UIPopOverController in combination with UIImagePickerController to let the user select an image from their iPad (with sourceType UIImagePickerControllerSourceTypeSavedPhotosAlbum). This works great and as expected, but it only allows the client to browse the SavedPhotos album obviously. If I change the picker to use UIImagePickerControllerSourceTypePhotoLibrary, the window will still display its albums, but it'll be static (meaning I can scroll, but I can't select albums, and when I scroll down or up, the view will only pop back if I tap the screen again).
Does the PhotoLibrary require extra settings to work properly? I tried numerous approaches but I'm all out of luck here.
The setup is an OpenGL view, on which I spawn the UIPopOverController with the UIImagePicker. For the sake of clarity, here's the code:
-(void)showPicker
{
if(![pController isPopoverVisible])
{
[pController presentPopoverFromRect:CGRectMake(50,100,200,300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
else
{
pController dismissPopoverAnimated:YES];
}
}
-(void)awakeFromNib
{
picker = [[UIImagePickerController alloc] init];
pController = [[UIPopoverController alloc] initWithContentViewController:picker];
// Code works properly if I only set it to UIImagePickerControllerSourceTypeSavedPhotosAlbum
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
else if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) picker.sourceType =UIImagePickerControllerSourceTypeSavedPhotosAlbum;
else { NSLog(#"Error: Could not pick appropriate sourceType"); }
picker.mediaTypes = [NSArray arrayWithObjects:(NSString*)kUTTypeImage, nil];
picker.delegate = self;
pController.delegate = self;
picker.allowsEditing=NO;
}
Are you working with iOS6 ?
I know that in Settings/Privacy you have to allow your app to see in the Photos Albums.

Best way to use imagepickercontroller in iphone?

I am using UIImagePickerController to select the image from the PhotoLibrary in my application. I have used two different approaches for this. At first I have used a class variouble UIImagePicker with below code.
imagepicker = [[UIImagePickerController alloc]init];
imagepicker.delegate = self;
imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagepicker.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:self.imagepicker animated:YES];
Above code is working fine.But when I clicked on the button it is taking some time to react with the animation in this case.Then I used the autorelease pool approach with this method
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker= [[[UIImagePickerController alloc]init]autorelease];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:picker animated:YES];
}
[pool release];
Also works charm. Both of them showing no leak in the analyser.Can anybody point me the right approach.
Well, no much to say here... Both approaches work, both approaches are correct, use whichever you prefer.
One minor point: if you are regularly presenting the image picker, you better use the first method, and assign it to an instance variable (it isn't called a "class variable"!) only for the first time, and don't release it until - dealloc - this way, you save the continuous allocation-deallocation of the image picker every single time the user chooses an image.

iOS SDK: Launch the Camcorder (video camera), not the still camera

I'm using the following code to launch the still camera on the iPhone.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
I'm wondering how I can launch only the video camera, and not the still camera. I need this view without the switch in the bottom right.
Any ideas?
You will have to add these two lines to launch in video camera mode.
picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
You can also limit it to the video mode and hide the switch by only enabling the appropriate media type. Do this to allow only video mode,
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
You will however need to add MobileCoreServices.framework for this and #import <MobileCoreServices/MobileCoreServices.h>.
Try adding
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;

Using UIImagePickerController in the game

I want to make a game, where the user can touch a picture of a TV and then choose a picture from their photo library.
I had success working with UITextFields, adding them to my EAGLView as subviews But I haven't been able to do the same thing with an UIImagePickerController , which seems the only way to do what I want to do.
Any help is appreciated !
UPDATE
With the suggestion of zpasternack I managed to make the menu appear by adding the UIImagePickerControllerDelegate, UINavigationControllerDelegate and using this method:
- (void) chooseImageFromLibrary {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsEditing = YES;
[self addSubview:imagePickerController.view];
[imagePickerController viewWillAppear:YES];
[imagePickerController viewDidAppear:YES];
}
I call the chooseImageFromLibrary method at the start. It shows the interface, but as soon as i hit cancel or choose the app stops.
Can anyone suggest me:
1) How to make the cancel and choose buttons work.
2) How to call the UIImagePickerController whenever I want ( by calling chooseImageFromLibrary again ??).
3) When the user hits choose..Where do i find the UIImage the user just picked to ?, how do i pick it ?
Thanks.
I've never used one over an EAGLView, but UIImagePickerControllers are typically invoked with presentModalViewController, like:
- (void) chooseImageFromLibrary {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsEditing = YES;
[self presentModalViewController:imagePickerController animated:YES];
}
Nervermind, problem solved. i just needed to overwrite some functions to make use of the UIImagePickerController.