Search code examples
iphoneobjective-cios4uibutton

How to open camera while I click the UIButton in iPhone?


I am trying to open the camera when I click the UIbutton in iPhone app. I want to store the captured image in a location that I specify.


Solution

  • You need to use something like this

    - (IBAction)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];
    }
    
    
    - (IBAction)saveImage:(id)sender {
        if(imageView.image) {
            [self showProgressIndicator:@"Saving"];
            UIImageWriteToSavedPhotosAlbum(imageView.image, self, @selector(finishUIImageWriteToSavedPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
        }
    }