Dayn Goodbrand
Dayn Goodbrand

Reputation: 611

Save photo on use button click in camera app

My current code is :

- (IBAction)cameraButtonAction:(id)sender {   
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.allowsEditing = NO;
    picker.sourceType = (sender == cameraButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES]; 
}

This is bringing up the default camera, but when I select use it does not save the picture. I have tried :

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [self dismissModalViewControllerAnimated:YES];
}

Every tutorial i have looked at, they make a custom camera app using a UIImageView but this is not what I want to do, I do not want to display the image back in the app and want to keep the default camera functions.

Upvotes: 0

Views: 963

Answers (1)

Midhun MP
Midhun MP

Reputation: 107121

Your code is correct. But you didn't set the delegate

You are missing a single line here:

picker.delegate = self;

You need to add that in your cameraButtonAction method.

- (IBAction)cameraButtonAction:(id)sender
{   
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = NO;
    picker.sourceType = (sender == cameraButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES]; 
}

Upvotes: 1

Related Questions