Ive been trying to set up a small iOS method that takes a picture automatically when user opens the app. After much research i finally found this iOS taking photo programmatically and after a little more i found this from apple https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html can someone help me get started in setting up a method for captureStillImageAsynchronouslyFromConnection:completionHandler:
i don't want any interaction from said user. thanks
Asked
Active
Viewed 191 times
-1
-
Why would you need the capture to be asynchronous? – Lyndsey Scott Feb 06 '15 at 05:06
-
i would like to take a picture programmatically without any user input – mo bonus Feb 06 '15 at 06:15
-
You don't need to capture the image asynchronously for that... Just create a uiimagepicker as described in the 2nd answer of iOS taking photo programmatically and call takePicture: http://stackoverflow.com/a/23312505/2274694 – Lyndsey Scott Feb 06 '15 at 06:18
-
Id like to use AvFoundation. that method didn't work either, its just opened the camera. I think it'd be fun to play with the device snapping a picture onload instead of user interaction and am still looking for a specific method – mo bonus Feb 06 '15 at 06:19
-
id like to use whatever is easiest and a lot of other answers I read on this site point to AVFoundation over UIImagePicker for creating customizable instances of camera functionality stuff – mo bonus Feb 06 '15 at 06:23
1 Answers
1
Even though you seem to want to do the call asynchronously and using AVFoundation
, I still recommend simply using a UIImagePickerController
in this case, ex:
- (void)viewDidLoad {
[super viewDidLoad];
// If the device has a camera...
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// Create an image picker
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
imagePickerController.showsCameraControls = NO;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:^{
// And take the picture after a short delay
// to give the view and image picker time to get
// ready
[self performSelector:@selector(takepic:) withObject:imagePickerController afterDelay:2];
}];
}
}
// Automatically take the picture using the
// image picker passed in as a parameter
- (void)takepic:(UIImagePickerController*)imagePickerController {
[imagePickerController takePicture];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// ... Do whatever with the image ...
[picker dismissViewControllerAnimated:YES completion:nil];
}

Lyndsey Scott
- 37,080
- 10
- 92
- 128