• Articles
  • Tutorials
  • Interview Questions

IOS Camera

Building an iOS Camera App

Camera is a device which is used to take the images. In iOS UIImage PickerController class permits programmers to show the familiar Camera interface to their users and ask them to take a photo or shoot a video. The photos taken or the videos shot by the user with the UIImagePickerController class then become accessible to the programmer.

Step 1. Create an View based application.
Step 2. Add a button in ViewController.xib and create IBAction for the button.
Step 3. Add an image view and create IBOutlet like as viewImage.
Step 4. Change ViewController.h as follows –

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIImagePickerControllerDelegate>
{
UIImagePickerController *imagePicker;
IBOutlet UIImageView * viewImage;
}
- (IBAction)showCamera:(id)sender;
@end

Learn about the associated functions with the address book in our blog on iOS Address Book.

Step 5. Change ViewController.m as follows –

#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)showCamera:(id)sender {
imagePicker.allowsEditing = YES;
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else{
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (image == nil) {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
viewImage.image = image;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissModalViewControllerAnimated:YES];
}
@end

Check out our iOS Developers Interview Questions to ace your next interview!

Course Schedule

Name Date Details
iOS Development Training 05 Oct 2024(Sat-Sun) Weekend Batch
View Details
iOS Development Training 12 Oct 2024(Sat-Sun) Weekend Batch
View Details
iOS Development Training 19 Oct 2024(Sat-Sun) Weekend Batch
View Details

About the Author

Technical Research Analyst - Spring Core & Spring Boot

Rahul, a Technical Research Analyst with a focus on Spring Core & Spring Boot, combines a love of coding with an aptitude for deciphering intricate technical ideas. His writing sheds light on the complexities of software development, providing both readability and insightful analysis.