take photo Using the storyboard or Xib in Xcode

I want to take a photo with Stroyboard (because I don't have iPhone )

know I have code Take photo and the select

and then

What's the easiest way to resize/optimize an image size with the in iPhone

.H

#import <UIKit/UIKit.h>

@interface APPViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@property (strong, nonatomic) IBOutlet UIImageView *imageView;

- (IBAction)takePhoto:  (UIButton *)sender;
- (IBAction)selectPhoto:(UIButton *)sender;

@end

.M

#import "APPViewController.h"

@interface APPViewController ()

@end

@implementation APPViewController

- (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

Answers


You have to check the Camera is available or not for that using UIImagePickerController of

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;

For your scenario you should write takePhoto method like that :

- (IBAction)takePhoto:(UIButton *)sender {
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            //Do your stuff here
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message: @"Camera is not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];      
        }
    }

EDIT:

Using Simulator you can't take photo. You must require device from take photo or open camera.

may it will help you.

Happy coding...:)


Need Your Help

React & SVG: How do I make <path> support onClick?

svg onclick reactjs

This is what React SVG currently supports: http://facebook.github.io/react/docs/tags-and-attributes.html#svg-attributes

JMeter command line - linux version vs windows version

windows linux apache jmeter

I'm been using JMeter on a linux box, under the command line for a little bit. works fine.