Taking photo and video on iOS device - ios

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.

Related

How to pass image from one page to another in ios

i want to pass image from one page to another by selecting image from gallery or using camera.whe user click on display button image will be tranfered to next page
i have tried this. but not working in .m file
#interface ImagePicker () <UIImagePickerControllerDelegate>
{
IBOutlet UIImageView *imageview;
UIImageView *fordisplay;
}
#end
#implementation ImagePicker
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)clickOnDate:(id)sender
{
datePicker *date=[[datePicker alloc]initWithNibName:#"datePicker" bundle:nil];
[self.navigationController pushViewController:date animated:YES];
}
-(IBAction)selectPhoto:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
-(IBAction)takePhoto:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
DisplayImage *obj_display1=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.imageview.image = chosenImage;
imageview.image=chosenImage;
obj_display1.imageDisplayy=chosenImage;**
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(IBAction)display:(id)sender
{
DisplayImage *obj_display=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
[self.navigationController pushViewController:obj_display animated:YES];
}
and in next page where want to display image
.h file
#property(nonatomic,strong) UIImageView *imageDisplayy;
.m file
#synthesize imageDisplayy;
- (void)viewDidLoad {
[super viewDidLoad];
obj_imageview.image=imageDisplayy;
}
You are creating an instance of DisplayImage in your this method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
While performing navigation you are creating another new instance which doesn't have imageDisplayy property set for it.
-(IBAction)display:(id)sender
{
DisplayImage *obj_display=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
[self.navigationController pushViewController:obj_display animated:YES];
}
One solution for this problem is make DisplayImage *obj_display1 as property in your ImagePicker.
#property(nonatomic,strong) DisplayImage *obj_display1;
Instantiate it in viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.obj_display1=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
}
update code in this method as
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.imageview.image = chosenImage;
imageview.image=chosenImage;
self.obj_display1.imageDisplayy=chosenImage;**
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Then perform navigation
-(IBAction)display:(id)sender
{
[self.navigationController pushViewController:self.obj_display1 animated:YES];
}
Your are directly passing image to imagview.Instead of that pass image from one view controller to anorther.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
DisplayImage *obj_display1=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.imageview.image = chosenImage;
imageview.image=chosenImage;
obj_display1.imageDisplayy=chosenImage;**
[picker dismissViewControllerAnimated:YES completion:NULL];
}
next page where want to display image
.h file
#property(nonatomic,strong) UIImage *imageDisplayy;
.m file
#synthesize imageDisplayy;
- (void)viewDidLoad {
[super viewDidLoad];
obj_imageview.image=imageDisplayy;
}
try this :
//In .h file
// change your property to UIImage instead of imageview
#property(nonatomic,strong) UIImage *imageDisplayy;

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

iOS how to start the image picker

I have a UIButton and when the user clicks it, I want to start the image picker controller
I already configure what I think it is enough but I couldn't know what is the message that I have to pass to that image picker to start working
This is my code
#import "ImagePickerViewController.h"
#interface ImagePickerViewController ()
#property (weak, nonatomic) IBOutlet UIImageView *image;
#end
#implementation ImagePickerViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)SelectImage:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
#end
I have already set the correct protocols:
#interface ImagePickerViewController : UIViewController < UINavigationControllerDelegate,UIImagePickerControllerDelegate>
#end
You need to present the UIImagePicker
- (IBAction)SelectImage:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:NO completion:nil];
}
You can show the picker with:
[self presentViewController:imagePicker animated:YES completion:NULL];
And then in your delegate callback imagePickerController:didFinishPickingMediaWithInfo you get the image and dismiss the picker again:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerEditedImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
You have to tell your view controller class to show the UIImagePickerController.
Simply use
[self presentViewController:imagePicker animated:YES completion:nil];
This will present it modally. If you are running on an iPad, you instead have to present it in a popover controller, as follows:
Declare a new property in the #interface:
#property (nonatomic, strong) UIPopoverController* imagePickerPopover;
Present the popover controller e.g:
UIButton* button = sender;
self.imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:self.imagePicker];
[self.imagePickerPopover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

UIImagePickerController camera blank snapshot image

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

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