title and description for camera click images - iphone

In my camera app i want when i click an image it will ask for title and description from the user and then save it.right now its saving images but not asking for title and description.I am new to iOS.so,may be this is a silly question.please help me to get this.for camera click i am using this method:-
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
BOOL camera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if(camera)
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[[picker navigationBar]setBarStyle:UIBarStyleDefault];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[picker setDelegate:self];
[self presentViewController:picker animated:YES completion:NULL];
[picker release];
}

You can do it in the following way:
Click the image using camera.
Come back to your app without saving the image. You'll have a reference of the image clicked in your application till now.
ask the user for the title & description.
Save the image to picture library using this line of code:
UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void contextInfo);
Hope it helps you.
More Help Here....

For me this tutorial guided me to achieve what i want.So, i think to share the link.May be someone gets benefited.
http://www.raywenderlich.com/13541/how-to-create-an-app-like-instagram-with-a-web-service-backend-part-22
and this piece of code helps me out..
-(void) takePhoto{
BOOL camera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if(camera)
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[[picker navigationBar]setBarStyle:UIBarStyleDefault];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[picker setDelegate:self];
[self presentViewController:picker animated:YES completion:NULL];
[picker release];
actionSheetbool = false;
}
else
{
UIAlertView* cameraAlert = [[UIAlertView alloc]initWithTitle:#"Sorry!!" message:#"Camera not found." delegate:nil cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[cameraAlert show];
[cameraAlert release];
}
}
-(void)photoLibrary{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
[imagePicker release];
actionSheetbool = false;
}
}

Related

Getting an image from the iPhone camera roll

I currently have a UIImageView and a UIImage. How do I allow the user to select one of their photos from the camera roll?
There are possible duplicates, but I've had no luck. This might possibly be because I don't hook things up in the Interface Builder.
I would like something simple like UIImage * image = [UIImage imageFromCameraRoll], but unfortunately, that's not possible (I don't think so, at least).
Try this code
It is help to you get image from cameraroll & photolibrary. using UIImagePickerViewController
if you take Picture
From camera (in both open As UINavigationcontroller).
From Gallery(for ipad open as UIpopovercontroller & for iphone open as nvigationcontroller).
First set delegate
#interface camera : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIPopoverControllerDelegate>
get image from Camera
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = YES;
imagePicker.wantsFullScreenLayout = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
newMedia = YES;
iscamera = 0;
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error to access Camera"
message:#""
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
Get image from Gallery
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *_picker=nil;
if (popoverController) {
[popoverController dismissPopoverAnimated:NO];
}
_picker = [[UIImagePickerController alloc] init];
_picker.delegate = self;
_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_picker.wantsFullScreenLayout = YES;
//[popoverController presentPopoverFromBarButtonItem:sender
// permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self presentViewController:_picker animated:YES completion:nil];
} else
{
popoverController = [[UIPopoverController alloc] initWithContentViewController:_picker];
[popoverController setDelegate:self];
[popoverController presentPopoverFromRect:btn.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error access photo library"
message:#"your device non support photo library"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
Both Result you get in Delegate Method
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// write your code here ........
}
Use UIImagePickerController, see the Apple docs.
Select the source type:
#property (nonatomic) UIImagePickerControllerSourceType sourceType
From on on these:
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum

UIImagePickerController,Check camera

-(void)viewDidLoad
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = NO;
[self.view addSubview:imagePicker.view];
}
else
{
// UIAlertView…
}
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:NO];
}
I want to put out an alert when you do not have a camera.
IPhone app launch and move in this code.
But, Crash (This Error >
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CameraAppDelegate class])); > Thread 1: signal SIGABRT) when run in a simulator.
Why is this?
use this code and add UIImagePickerControllerDelegate delegate in .h file
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.wantsFullScreenLayout = YES;
[self presentModalViewController:picker animated:YES];
}
else
{
UIAlertView *altnot=[[UIAlertView alloc]initWithTitle:#"Camera Not Available" message:#"Camera Not Available" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
altnot.tag=103;
[altnot show];
[altnot release];
}
Create NSObject Class and name it like ClsGlobal, or the name you want..
then write +(BOOL)isCameraDeviceAvailable in your ClsGlobal.h and implement below function in ClsGlobal.m.
+(BOOL)isCameraDeviceAvailable
{
BOOL isCameraAvailable=NO;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
isCameraAvailable = YES;
}
return isCameraAvailable;
}
Use this class method, It will return YES if camera available else return NO.
Now you can call this method using [ClsGlobal isCameraDeviceAvailable]; means your if Condition looks like if([ClsGlobal isCameraDeviceAvailable]).
This method will help you throughout your project in any controller, You have to just import ClsGlobal like #import "ClsGlobal.h".

Open camera view upon app Startup (iOS6)

what im trying to do is to have the app open up with the camera as the first screen. It isn't working and i don't know what im missing. If anyone can fill me in that would be wonderful... Thanks.
- (void)viewDidLoad
{
[super viewDidLoad];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
}
Try like that. Hope it helps you:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];

how to take picture from camera using iphone app

I have implemented picture taking while pressing UI Button butwhen ever i pressed the button got app crashed.
Here is the source code.
.h file
#interface Camera : UIViewController
<UIImagePickerControllerDelegate>
{
UIImagePickerController *mPicture;
}
#property (nonatomic, retain) UIImagePickerController *mPicture;
.m file
#implementaion Camera
#synthesize mPicture;
-(void)pictureButtonPushed
{
UIImagePickerControllerSourceType mType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:mType])
{
mPicture.sourceType = mType;
[self presentModalViewController:mPicture animated:YES];
}
}
Thanks in advance
Try this one
Hope it will help :)
-(IBAction)takePhoto
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
}
// image picker needs a delegate,
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
-(IBAction)chooseFromLibrary
{
UIImagePickerController *imagePickerController= [[UIImagePickerController alloc]init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
// image picker needs a delegate so we can respond to its messages
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
//delegate methode will be called after picking photo either from camera or library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[myImageView setImage:image]; // "myImageView" name of any UImageView.
}
Here is the code for what you want
- (void)cameraPressed
{
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle:#"Set a Prifile Picture"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Choose From Library",#"Take a New Photo",nil];
[menu showInView:[self.navigationController view] ];
}
// actionsheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
#try {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.navigationBar.barStyle = UIBarStyleBlack;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
[appDelegate.objList setHidden:TRUE];
appDelegate.strRefreshCamera = #"notupdate";
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
else {
[appDelegate showAlertWithTitle:#"Info" message:#"This function needs a camera which is only available on the iPhone or iPod."];
}
}
#catch (NSException *e) {
}
}
if (buttonIndex == 0) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.navigationBar.barStyle = UIBarStyleBlack;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
[appDelegate.objList setHidden:TRUE];
appDelegate.strRefreshCamera = #"notupdate";
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//flag = TRUE;
[self dismissModalViewControllerAnimated:YES];
//[appDelegate showLoadingView];
UIImage *capturedImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
Use this image object where ever you want to use.

Display same default camera application using UIImagePickerController

How can we display the UiImagepicker controller interface with both camera and video mode and also with Photo Library icon button,same as default camera App for iPhone.
or How to remove cancel Button (shown in Camera view) and replace with different button. Is it possible and if will apple approve this approach.
Please help me out ??
You can try this way.
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if(hasCamera){
UIActionSheet *actionSheet;
actionSheet = [[[UIActionSheet alloc] initWithTitle:#"Add Photo"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Select from Library", #"Take a New Photo", nil] autorelease];
actionSheet.actionSheetStyle = UIBarStyleBlackOpaque;
[actionSheet showInView:[self view]];
}
else {
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.allowsEditing = YES;
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
Actionsheet delegate method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.allowsEditing = YES;
imagePickerController.delegate = self;
if(buttonIndex == 0)
{
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else if(buttonIndex == 1)
{
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
Image picker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
if(image)
{
[self.addPhotoButton setBackgroundImage:image forState:UIControlStateNormal];
}
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}