Automatically take a Picture - ios

I have tried to take a picture and save it to the photo library automatically with UIImagePicker and AVFoundation, but I couldn't make it work.
I would like to take the photo when the view appears, not showing the camera view to the user, and then use it as a simple image in the app.
Thanks

Apple actually has an entire guide devoted to this sort of thing, "Camera Programming Topics for iOS," with a subsection "Taking Pictures and Movies." There's even a sample project, "Photo Picker." Here's an excerpt, the action method for your take-a-picture button:
- (IBAction)cameraAction:(id)sender {
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}
Note: It won't work unless [UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] returns YES, indicating that the device has a camera.

Related

multiple pictures with UIImagePickerController

i've been searching around the web but couldn't find an answer.
basically i wanna take two photos one right after the other.
i'm using UIImagePickerController to show a picker and implementing didFinishPickingMediaWithInfo.
when it gets called i'm checking my count so that if its one, i implement a block and pass it to dismissViewControllerAnimated like this:
if(1 == count) {
void (^simpleBlock)(void);
simpleBlock = ^{
[self useCamera];
};
[self dismissViewControllerAnimated:NO completion:simpleBlock];
}
it all seems to work fine, and even the useCamera method is called.
the problem is that the second time the picker shows i see all of its controls but i don't see on the screen the image from the camera.
any help would be appriciated.
i managed to work it out with replacing the call to useCamera with:
[self performSelector:#selector(useCamera) withObject:nil afterDelay:0.3];
i think my question has some relation to: iOS 7 UIImagePickerController has black preview
since the delay fixed the problem.
For you to save time. You can use available library out there. These are my good choices. CTAssetsPickerController ELCImagePickerController
UIImagePickerController helps to access the default camera app in iOS.
It will allow only limited functionalities like take picture/video, photo album.

UIActionSheet button mask messed up after showing QLPreviewController

I am working on a photo-sharing app. The users can take and upload photos, and I use an UIActionSheet to provide selection whether to take a new photo with the camera or choose an existing photo from the library. In an other view I have a list of uploaded photos, and if the user taps on a photo it becomes full screen with QLPreviewController. My problem is that if the preview controller was once opened in full screen, in the completely different view controller of upload the button masks of the action sheet messes up this way:
Any idea how to avoid this (obviously) bug of the framework?
It should be issue with statusBarOrientation.
Try to add
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
in viewWillAppear:.

Is it necessary to check if camera exists when targeting iOS 6+?

I am making an app that makes use of the camera in multiple areas and it came upon me that all devices that support iOS 6+ have a camera. This is more of a programming practice question than a practical implementation question.
Apple never explicitly recommends that you have to check for a camera, but many developers do.
Is it safe to not check? What are the implications of NOT checking for a camera?
Is there any performance advantage/disadvantage?
Thanks,
Virindh Borra
From the docs for the UIImagePickerController isSourceTypeAvailable: method:
Because a media source may not be present or may be unavailable, devices may not always support all source types. For example, if you attempt to pick an image from the user’s library and the library is empty, this method returns NO. Similarly, if the camera is already in use, this method returns NO.
Before attempting to use an UIImagePickerController object to pick an image, you must call this method to ensure that the desired source type is available.
So yes Apple does tell you to check. Besides, how hard is it to do:
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
// show camera
} else {
// don't show camera
}

UIImagePickerController shows last picture taken instead of camera input

I'm having a strange behaviour within my app.
For taking pictures i'm using the following pretty standard code for displaying the UIImagePickerController:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
It works perfectly fine the first time I tap the button which calls this action. The strange behaviour starts when I tap that button again. The UIImagePickerController starts again BUT it doesnt show the input from the camera anymore. It shows the last picture I've taken.
More Details of this state:
Tapping on the image shows the yellow square of the auto focus. (which it actually uses to focus the camera correctly)
When I tap on the ImageCapture button -> the correct image is taken and presented on the screen.
If I take a picture and press 'Retake' the regular camera image is presented as input.
More weirdness: It has nothing to do with the iPad I'm using. Creating a new example app which only has button which calls the code from above everything works perfectly fine.
I assume it has something to do with the configuration of the app. Therefore I checked everything but could not find any differences which may cause this issue.
Thanks in advance for any advice!
Update:
I do implement the UIImagePickerControllerDelegate in order to dismiss the UIImagePickerController.
In reading the Apple documentation on UIImagePickerController doc here it states that "When the user taps a button to pick a newly-captured or saved image or movie, or cancels the operation, dismiss the image picker using your delegate object. For newly-captured media, your delegate can then save it to the Camera Roll on the device. For previously-saved media, your delegate can then use the image data according to the purpose of your app." Maybe you need to implement the UIImagePickerContriollerDelegate protocol methods and properly dismiss the existing UIImagePickerController object. See UIImagePickerControllerDelegate
I finally did find the issue: It was a category on UIViewController I used somewhere else in the project. As soon as I compiled it with my project, the UIImagePickerController acted weird. So I think I somehow managed to use a method name which is also used internally by UIImagePickerController. It still confuses me a little since the category wasn't used on the UIImagePickerController at all.

how can i make a custom, in-app camera for my iphone app developed in xcode?

i am making a photography iphone app and am after, upon the app being launched, the screen to be a large image where the camera is shown in the center through a hole in the picture - this should be a similar look to that of hipstamatic. since the camera would be open upon launch, i would also need a button to take the picture (but that is not a priority at the moment). i am wondering whether there is an easy way to do what i have described? so far, research has pointed me towards using the uiimagepickercontroller, but using just this did not give me nearly the amount of customization i am after - or am i mistaken and i can do as i described using the uiimagepickercontroller?
right now, this is the code i'm using for the camera - it's currently an ibaction linked to a button that launches the camera once clicked. however, as i mentioned, i would like the camera to open on its own upon opening the app
self.picker = [[UIImagePickerController alloc] init];
self.picker.allowsEditing = NO;
[self.picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.picker animated:NO];
[picker release];
this code not only navigates away from the current view, but it has all the controls (zoom, tap to focus, etc.), is full screen, and plays that silly animation of the lens opening.
anything you have to offer would be greatly appreciated.
many thanks in advance
zach
Use the showsCameraControls and cameraOverlayView properties of UIImagePickerController to add custom overlay above the picker (using a view with a transparent background in which you add some elements as subviews to overlay / frame / mask some parts of the picker if needed.)
You can even use the cameraViewTransform to change the size and position (i.e. the transform) of the camera view that is capturing the camera image.

Resources