UIImagePickerController tutorial? [closed]

2020-02-09 04:16发布

问题:


Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 4 years ago.

I am currently developing an application and I need to be able when pressing a button to open the camera and take a snapshot that I will attach to a .json file and send to my server. I am searching on google and StackOverflow for the last couple of hours but all the tutorials seem very old (08'-09') or not match my needs. I know that all the work is done with UIImagePickerController class but I would like to have a working example. Does anyone know a good tutorial to get started for something like this?

回答1:

Well if you google something like:

UIImagePickerController and take snapshot put in json and send to server

Will be a bit hard. So, use this tutorial for the UIImagePickerController. By the way, the term for the search was:

UIImagePickerController Tutorial 2012



回答2:

You should check this article from AppCoda Build a Simple iPhone Camera App, very clear and simple :)

Take photo using the native iOS Camera app

- (IBAction)takePhoto:(UIButton *)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:nil]; 
}

Read the captured photo (you have to implement UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imageView.image = chosenImage;

    [picker dismissViewControllerAnimated:YES completion:nil];
}


回答3:

I came across this code AQPhotoPicker. This is quite easy to use with only one call, you will get photo from camera or photoPicker



回答4:

Try this. It's very simple, you just need to set delegate for a controller and call it. Google will help you, there are plenty of resources and working examples. For instance, sample code from Apple