UIImagePickerController camera blank snapshot image - ios

I'm trying to take a picture using the UIImagePickerControllerSourceTypeCamera.
When I'm capturing a photo in the snapshot after, I'm getting a blank photo, but if I choose Use photo I can see it I'm my UIImage:
also in the console im getting these error:
: CGAffineTransformInvert: singular matrix.
and
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)takePhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
_newMedia = YES;
}
}
- (IBAction)selectPhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
_newMedia = NO;
}
}
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
_imageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
-(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}

I have tested your code, its working fine. I think the issue you are facing is something related to this issue...
Snapshotting a view that has not been rendered results in an empty
snapshot. Ensure your view has been rendered at least once before
snapshotting or snapshot after screen updates.
Check this post; this might help you...
UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7
Here is complete code just incase if you are missing something...
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (nonatomic, weak) IBOutlet UIImageView *imageView;
- (IBAction)takePhoto:(id)sender;
- (IBAction)selectPhoto:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#import MobileCoreServices;
#interface ViewController ()
#property (nonatomic, readwrite) BOOL newMedia;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)takePhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
_newMedia = YES;
}
}
- (IBAction)selectPhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
_newMedia = NO;
}
}
//- (IBAction)takePhoto_
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
_imageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
-(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end

I found the solution to my problem thanks to DevC's comment pointing me in the right direction. I used an ActionSheet to present the UIImagePickerController, so when clicking a button on it the animation still runs while the picker is opened.
I solved it by closing the picker before I run the code that triggers thepicker:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[actionSheet dismissWithClickedButtonIndex:999 animated:NO]; //non-existing button index so it doesn't trigger anything again
// Rest of code here (UIImagePickerController trigger)
}

I encountered the same problem. If I copy the camera code to a new project,it can works well. So I think maybe it not the code's problem.
Finally,in my project, I found it caused by a third-party library which is about status bar.
self.MTStateBar = [[[MTStatusBarOverlay alloc] initWithFrame:CGRectMake(0, 0, 320, 20)] autorelease];
I solved this problem by replacing it. Wish this answer could help you.

UPDATE 3/15:are you using UIActionSheet to show UIImagePickerController? I solved it by replace UIActionSheet by UIAlertController. Because UIAlertView may will cause unexpected bugs.DO NOT USE UIAlertView anymore;)
I think it's a iOS's bug,you can delay 0.5s to present UIImagePickerController , it's working for me

Related

How to save the image captured using Camera and save in another ViewController?

How to save the image captured using Camera and save in another ViewController ?
I am making a Photo Gallery App. But i dont know how to save the Captured image and show it in collection view in another viewcontroller. Currently i am using UIImagePickerController to access iphone camera and library .Can anyone help me to do that.
Here is my code.
Thanks in advance
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Try This
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker release];
}
you can achieve it by adding NSNotificationcenter.
Class A - Where you select the image from camera
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
[[NSNotificationCenter defaultCenter] postNotificationName: #"GotNewImage" object: chosenImage];
}
Class B - Where you want to pass image after selection and show on collection view. Add Nsnotificationcenter for this class in Viewdidload
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(GotNewImage:) name:#"GotNewImage" object:nil];
//To get the image on Class B
-(void)GotNewImage:(NSNotification*)notification
{
UIImage * newImage = (UIImage*) notification.object;
//Now do whatever you want to do with your image...
//Add in collection view and reload the collection view
}

Simulator Crashing When Running UIImagePickerController Xcode 7

My iPhone 5 simulator is crashing when I am trying to open a UIImagePickerController
my .m code:
#import "TestViewController.h"
#interface TestViewController ()
#end
#implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
#end
my .h code:
#import <UIKit/UIKit.h>
#interface TestViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)takePhoto: (UIButton *)sender;
- (IBAction)selectPhoto:(UIButton *)sender;
#end
This issue has been really annoying and I would really appreciate an answer. The code is to select an image from the photo library. I have the frameworks: Foundation, UIKit and CoreGraphics added into my project!
Thanks in Advance!
The camera is not available in the simulator.
You already made the check but you didn't set the picker.sourceType property :
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self.navigationController presentModalViewController:picker animated:YES];
Add this in your info.plist
Camera :
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) camera use
Photo Library:
Key : Privacy - Photo Library Usage Description
Value : $(PRODUCT_NAME) photo use
I fixed it by changing it from UIImagePickerControllerSourceTypePhotoLibrary to UIImagePickerControllerSourceTypeSavedPhotosAlbum

Taking photo and video on iOS device

Im trying to be able to take and capture a photo and show it in a uiimage view AND/OR take a capture a video and play it back in a movieplayercontroller.
I am able to click a button and "Take Photo" which does display in my uiimageview just fine. However the image disappears out of the uiimageview if i click a button to "Take Video" The take video works and displays back fine but like a said my uiimage has now disappeared.
If i go back to re take the photo the video i captured disappears?
.h file
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/MobileCoreServices.h>
#interface addEventViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>{
UIImagePickerController *imagePicker;
UIImage *eventPhoto;
IBOutlet UIImageView *imageView;
}
-(IBAction)TakePhoto;
- (IBAction)takeVideo:(id)sender;
#property (copy, nonatomic) NSURL *movieURL;
#property (strong, nonatomic) MPMoviePlayerController *movieController;
#end
.m file
#import "addEventViewController.h"
#interface addEventViewController (){
}
#end
#implementation addEventViewController
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
// FOR THE TAKE PHOTO
eventPhoto = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage: eventPhoto];
[self dismissViewControllerAnimated:YES completion:NULL];
// FOR THE TAKE VIDEO
self.movieURL = info[UIImagePickerControllerMediaURL];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
//FOR THE TAKE PHOTO
[self dismissViewControllerAnimated:YES completion:NULL];
// FOR THE TAKE VIDEO
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
// TAKE PHOTO BUTTON
-(IBAction)TakePhoto{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[imagePicker setSourceType: UIImagePickerControllerSourceTypeCamera];
[self presentViewController: imagePicker animated:YES completion:NULL];
}
// TAKE VIDEO BUTTON
- (IBAction)takeVideo:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)viewDidAppear:(BOOL)animated {
self.movieController = [[MPMoviePlayerController alloc] init];
[self.movieController setContentURL:self.movieURL];
[self.movieController.view setFrame:CGRectMake (420, 76, 320, 200)];
[self.view addSubview:self.movieController.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.movieController];
[self.movieController play];
}
- (void)moviePlayBackDidFinish:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I haven't actually compiled and run your code, but looking at it, you're defining imagePicker in the class instance, whereas you're defining picker inside the TakePhoto method. My guess is that when you run through the process, the method instance is being destroyed once it completes.
Instead, try using a single imagePicker instance declared at the class level, set its properties differently depending on whether the user is loading an image or video, and set the selected media accordingly.

Pass image from camera to view from storyboard

Something strange is happening with my code.
Scenario: Open camera->Take picture->Pass the image taken to a viewcontroller(from a storyboard.
The thing is that my UIimage variable from the destination view is not available, not recognized!
My code
postviewController.h
#import <UIKit/UIKit.h>
#interface postAlertViewController : UIViewController
#property (nonatomic, retain) UIImage *cameraImage;
#end
postviewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *aImageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 60, self.view.frame.size.width,150 )];
aImageview.image=cameraImage;
[self.view addSubview:amageview];
}
Take picture and pass it to the view controller above
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:NULL];
ViewController *postView = [self.storyboard instantiateViewControllerWithIdentifier:#"postview"];
postView.cameraImage=(UIImage *)[info objectForKey:UIImagePickerControllerEditedImage];
[self.navigationController pushViewController:postView animated:YES];
}
The stroryboard ID is set to "postview".
What i am getting is:
Property 'cameraImage' not found on object of type 'ViewController *'
Why cameraImage is not available from the origin view although is declared in destination's .h file?
In another situation where i needed to pass a string between views, in same manner as above
[yourViewController setValue:mysc.title forKey:#"sendAlertTitle"];
worked ok.
Any help?
Thank you.
try this
postAlertViewController *postView = [self.storyboard instantiateViewControllerWithIdentifier:#"postview"];
and always use class and interface name start with capital
you can use this one for more ease.
- (IBAction)captureImage:(id)sender
{
if (! [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *deviceNotFoundAlert = [[UIAlertView alloc] initWithTitle:#"No Device" message:#"Camera is not available"
delegate:nil
cancelButtonTitle:#"Okay"
otherButtonTitles:nil];
[deviceNotFoundAlert show];
} else {
UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPicker.delegate =self;
// Show image picker
[self presentViewController:cameraPicker animated:YES completion:nil];
}
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
UIImage *selectedImage =[info objectForKey:UIImagePickerControllerOriginalImage];
ViewControllerName *Vc=[self.storyboard instantiateViewControllerWithIdentifier:#"captioEdit"];
Vc.postImgStr=[self scaleAndRotateImage:selectedImage];
[picker dismissViewControllerAnimated:YES completion:nil];
[self.navigationController pushViewController:captioViewEdit animated:YES];
}
//Delegate method of UIImagePickerController for image picker model cancel
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
Thanks

iOS: Screen no longer receives Touches after calling dismissModalViewController

I have two views. Very simple set up just to play around with the camera roll.
One view will bring up the camera roll using:
[self presentViewController:self.imagePicker animated:NO completion:nil];
which is triggered by a UIButton. It brings up the camera, everything's fine.
After taking a picture, I am calling the following to dismiss the controller:
[self dismissViewControllerAnimated:NO completion:nil];
Again, everything is working.
But the view that brings up the imagePicker Controller no longer receives touch (the UIButton will no longer brings up the camera again) after the Modal View is dismissed.
It will only start to receive touches again when I switch to another view and come back.
I have been searching for a solution to this problem but have not been successful in finding anything. Thanks in advance.
EDIT (Adding code):
In CameraController.m
This is where brings up the Camera Roll
(Subclass of UIViewController conforming to
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>)
//UIButton that brings up the imagePicker
- (IBAction)useCamera
{
[self prepareImagePicker];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
//Initializing ImagePicker
- (void)prepareImagePicker
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
self.imagePicker.delegate = self;
OverlayCameraView *cameraOverlay = [[OverlayCameraView alloc] initWithFrame:(CGRect){{0, 0}, 320, 480} andTheCameraController:self];
self.imagePicker.cameraOverlayView = cameraOverlay;
}
}
//Delegate Method when a picture is taken
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.imagePicker.delegate = nil;
[picker dismissViewControllerAnimated:NO completion:nil];
self.imagePicker = nil;
self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
In OverlayCameraView.m
//Camera Overlay Class (Subclass of UIView)
- (id)initWithFrame:(CGRect)frame andTheCameraController:(CameraController*)cameraController
{
if ((self = [super initWithFrame:frame]))
{
self.camera = cameraController;
//.…2 UIButtons set up
}
return self;
}
//Overlay Cancel Button
- (void) cancel
{
[self.camera dismissViewControllerAnimated:NO completion:nil];
}
//Overlay Take Picture Button
- (void) takeAPicture
{
[self.camera.imagePicker takePicture];
}
You should be calling dismissViewControllerAnimated on the picker not self via the UIImagePickerControllerDelegate methods.
[picker dismissViewControllerAnimated:NO completion:nil];
or if you are keeping a reference to it:
[self.imagePicker dismissViewControllerAnimated:NO completion:nil];
EDIT:
Based on the revised code, I believe
self.imagePicker.cameraOverlayView = cameraOverlay;
should be:
self.imagePicker.cameraOverlayView = cameraOverlay.view;
Also this will cause a +2 reference count and will leak if you are not using ARC:
self.imagePicker = [[UIImagePickerController alloc] init];
It should be for proper reference counting:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
self.imagePicker = picker;
[picker release];

Resources