Record Video/Take Picture switch in iPhone app? - iphone

So i got a iphone app that is a button and when you pressed it i want the camera view to pop up and i want to give the user a choice to take a picture or a video like in the default camera app the one switch thing.
Thanks!

What you are looking for is something called 'UIImagePickerController'
-(void) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
This method is the what would be called when you press your button(s), what i am doing here is I have two buttons, choosePhotoBtn, and takePhotoBtn, the both link to the same method.
If the button that was pressed (the sender) is choosePhotoBtn, then UIImagePickerControllerSourceTypeSavedPhotosAlbum is set as the UIImagePickerController's source type.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
bannerImage.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
These two methods are delegate methods. They get called when the modelViewController holding the UIImagePickerController is dismissed.
I would recommend this site, as it has a brilliant tutorial on how to use these functions.
http://icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/
This is where i learnt how to use these classes, it seems like the site has had a wordpress comment attack on it at the moment, and firefox is blocking it for me, but if u can get to the page. Its a great resource.

Related

UIImagePickerController takePicture

I want to use UIImagePickerController takePicture method.
the problem his that the UIImagePickerController is not show in the screen and the user cannot press the Use button to accept the img.
Is there is any way to skip this screen and go straight to :
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
for saving the image?
The only way that I have found to do this is to use a custom overlay for UIImagePickerController. You can do that with code akin to that below:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//create custom overlay and allocate it as "customOverlayView"
picker.cameraOverlayView = customOverlayView;
//do any other setup desired for picker
[self presentViewController:picker animated:YES completion:nil];
[picker release];
Now once the takePicture method is called, the delegate didFinishPickingMediaWithInfo: will be called immediately like you desire.

How to access camera of iPhone using phonegap app

I have a simple application developed for android which takes a photo, accessing the camera of device.
I want the same application to be run on iPhone. For android we write permissions for accessing camera in manifest file. How do you access the camera in iPhone. Where do we need to set up it. Can anyone please help me?
Thanks in advance
Use the Media Capture API in the latest code, or wait for 0.9.6:
http://docs.phonegap.com/phonegap_media_capture_capture.md.html
For accessing the camera in iPhone, you can use following code.
// Camera
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsImageEditing = YES;
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//[self presentModalViewController:imgPicker animated:YES];
[objParent presentModalViewController:imgPicker animated:YES];
[imgPicker release];
Let me know in case of any difficulty.
Below are the delegate method for camera.
Delegate Name: UIImagePickerControllerDelegate, UINavigationControllerDelegate
Methods:
#pragma mark UIImagePickerController delegate
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *imgCapturePhoto = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[imgPhoto setImage:imgCapturePhoto];
[self dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
Cheers

how do I implement "Choose Existing Photo" in my app like in default iphone phonebook?

I want to develop an app which has functionality same as iphone phonebook capturing image and choosing iamge,
what should I to use for doing such
I have made an UIImageView and a button for UIActionSheet,
now I want to perform "Take Photo" and "Choose Existing Photo" options in my app
help me out, I do appreciate
thanks in advance ....
Hey #Veer you need to use UIImagePickerController
check out the documentation
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
and check out this link
http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/
It has sample examples about the same.
Edit you can use these methods to get the image in you UIImageView object
- (void)selectPhotos
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

UIImagePicker not showing Original Image from Photos Library in OS 3.1.2

Holy Crap! Really... I'm frustrated with this problem that get me stuck with my apps for a week now.
Here is the code
- (IBAction)loadTheImage {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
If I set the source as SavedPhotosAlbum (Camera Roll), then it works OK. But when I set it to PhotoLibrary, it just returns nil. And this just happens in OS3.1.2. In OS4 it works OK (ie returns the original image just fine).
Anybody?
A given source may not always be available on every device. This could be because the source is not physically present or because it cannot currently be accessed.
Before attempting to use an UIImagePickerController object to pick an image, you must call [UIImagePickerController isSourceTypeAvailable:] method to ensure that the desired source type is available.

iPhone dev noob question: Invoking action explicitly on application launch

I just started getting into iPhone development. I have been mish-mashing tutorials and material from books in order to get my bearings straight. I come from a PHP and Java background... Objective-C is a bit quirky. But, I learn best by getting my feet wet.
Basically, I have these actions. getPhoto is bound to a couple of UIBarButtonItems in my view.
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIBarButtonItem *) sender == choosePhoto) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
theimageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
My goal is to invoke the same action once the application launches, automatically opening the Camera. How would I go about this?
EDIT:
As per this SO question you should actually place it in viewWillAppear or viewDidAppear
Add a similar method to the ApplicationDidFinishLaunching method in the app delegate.
Might be better to place the call in the ViewDidLoad of your root view controller