Advertisement
thieumao

Take Photo

May 6th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ViewController.h"
  2.  
  3. @interface ViewController ()
  4.  
  5. @end
  6.  
  7. @implementation ViewController
  8.  
  9. - (void)viewDidLoad {
  10.     [super viewDidLoad];
  11.     // Do any additional setup after loading the view, typically from a nib.
  12.     if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
  13.         UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Device has no camera" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  14.         [myAlertView show];
  15.     }
  16. }
  17.  
  18. - (void)didReceiveMemoryWarning {
  19.     [super didReceiveMemoryWarning];
  20.     // Dispose of any resources that can be recreated.
  21. }
  22.  
  23. - (IBAction)takephoto:(id)sender {
  24.     UIImagePickerController *picker = [[UIImagePickerController alloc]init];
  25.     picker.delegate = self;
  26.     picker.allowsEditing = YES;
  27.     picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  28.     [self presentViewController:picker animated:YES completion:NULL];
  29. }
  30.  
  31. -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(nonnull NSDictionary<NSString *,id> *)info
  32. {
  33.     UIImage *chonlua = info[UIImagePickerControllerEditedImage];
  34.     self.imageview.image = chonlua;
  35.     [picker dismissViewControllerAnimated:YES completion:NULL];
  36. }
  37.  
  38. -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  39. {
  40.     [picker dismissViewControllerAnimated:YES completion:NULL];
  41. }
  42.  
  43. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement