Per scattare una foto si usa la classe UIImagePickerController che si trova nel framework AVFoundation.
ViewController.h
@interface ViewController : UIViewController <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage
:(UIImage *)image editingInfo:(NSDictionary *)info;
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker;
...
ViewController.m
#import <AVFoundation/AVFoundation.h>
...
UIImagePickerController *picker1;
...
- (IBAction)GetPhotoClick:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setDelegate:self];
[picker setAllowsEditing:YES];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
...
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage
:(UIImage *)image editingInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
[image1 setImage:[image copy]];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
Il controller deve implementare le interfacce UIImagePickerControllerDelegate e UINavigationControllerDelegate.