UIImagePickerControllerDelegate not responding properly - iphone

I'm using the UIImagePickerController in iOS 4.2.1 on an iPhone 3Gs. I've previously used the deprecated method
- (void)imagePickerController: didFinishPickingImage: editingInfo:
without a problem. I have another app using the new didFinishPickingMediaWithInfo API in another app, and the method is never getting called by the picker once media is chosen.
//MyViewController.h
#interface MyViewController : UIViewController < UIImagePickerControllerDelegate, UINavigationControllerDelegate>
//MyViewController.m
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController new] autorelease];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:TRUE];
}
- (void)imagePickerController:(UIImagePickerController *)picker imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo{
//**NEVER CALLED**
}

you have
- (void)imagePickerController:(UIImagePickerController *)picker imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo
where you probably want
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

You have this:
- (void)imagePickerController:(UIImagePickerController *)picker imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo
Look like you repeated the 'imagePickerController:' part of that method.

Putting the picker in the autorelease pool may be your problem -- it probably doesn't stick around long enough to call its delegate. Retain it instead:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
And then in the delegate you can release it:
[picker dismissModalViewControllerAnimated:YES];
[picker release];

It may be that this line:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
is returning false. This happens if the user's photo library is empty; this would be true on the iPhone simulator, for example.
EDIT: As the other examples show, you've also mistyped the delegate method. It should be:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

This is program that i have used to upload video to webservice through iOS 4.2 on 3g
-(void)uploadeVideoClicked{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
ipc.allowsEditing=NO;
ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;
ipc.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:ipc.sourceType];
ipc.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
ipc.delegate = self;
[self presentModalViewController:ipc animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSMutableDictionary *infoDict = [[NSMutableDictionary alloc]init];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.image"]){
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"" message:#"You Select a image Please select Movie" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[myAlertView show];
[myAlertView release];
} else if ([mediaType isEqualToString:#"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
mAppDelegate.uploadType = #"Video";
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
[infoDict setValue:webData forKey:#"VideoUrl"];
[infoDict setValue:[[mAppDelegate.userInfoArray objectAtIndex:1]valueForKey:#"user_id"] forKey:#"user_id"];
//Call webService to upload video ;
}
[picker dismissModalViewControllerAnimated:YES];
[infoDict release];
}

Related

how to get video from iphone Library

i want to pick a Video from Library. here is my code.
picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
picker1.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker1.mediaTypes = mediaTypesAllowed;
[self presentModalViewController:picker1 animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
if ([picker isEqual:picker1])
{
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:#"public.movie"]){
NSLog(#"%#",info);
}
}
problem is when i select video from Library, simulator getting hanged. Even delegate method didFinishPickingMediaWithInfo not calling
Thanks in advance.
Try This
myImagePickerController.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
or refer this
UIImagePickerControllerMediaType
Hope this helps u

Iphone: Image picker is not working

I am implementing for imagePicker demo but it is not working.
When i click to pick image button ,nothing is happen. My code is as follow:
-(IBAction)pick:(id)sender
{
ipc=[[UIImagePickerController alloc]init];
ipc.delegate=self;
ipc.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
NSLog(#" %#",ipc.sourceType);
[ipc presentModalViewController:self animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[picker parentViewController]dismissModalViewControllerAnimated:YES];
[picker release];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
img.image=[info objectForKey:UIImagePickerControllerOriginalImage];
[[picker parentViewController]dismissModalViewControllerAnimated:YES];
[picker release];
}
please change ur code
[ipc presentModalViewController:self animated:YES];
to
[self presentModalViewController:ipc animated:YES];
The problem is you are trying to present the Modal view using:
[ipc presentModalViewController:self animated:YES];
Instead you should use:
[self presentModalViewController:ipc animated:YES];
How about this:
-(IBAction)pick:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker
animated:YES];
newMedia = YES;
}
-(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:YES];
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}

Error with UIImagePickerController

I have this code for send images on tweet. When I try the app, the picker works well but it doesn't grab the image. What's wrong?
- (IBAction)sendImageTweet:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSData *imageData = UIImagePNGRepresentation(image);
[self dismissModalViewControllerAnimated:YES];
[tweetViewController addImage:(UIImage *)imageData];
[self presentModalViewController:tweetViewController animated:YES];
}
You should use the constant, not an NSString and the key.
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

Capture Video as well as Images in iPhone

I am using ImagePickerController for Video Capturing. I need to save the capturing video as image also.
So I selected AVCaptureSession for capturing Images. I'm not able to run AVCaptureSession as well as ImagePickerController. So I need to give the ImagePickerController as input to the AVCaptureSession.
But I don't know how to do that. Please Help me.. and suggest me for the right way.
I found only these two. Hope its helps.
http://www.iphonedevsdk.com/forum/iphone-sdk-development/24025-uiimagepickercontroller-videorecording-iphone-3gs.html
UIImagePickerController: Getting image capture from video
I was having same issue.. I did work on image and video and used below code for image capturing:
- (void) snapImage: (id) sendern
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
ipc.allowsImageEditing = YES;
[self presentModalViewController:ipc animated:YES];
}
And for video recording i used below code:
- (void) recordVideo: (id) sender
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
ipc.allowsEditing = YES;
ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;
ipc.videoMaximumDuration = 30.0f; // 30 seconds
ipc.mediaTypes = [NSArray arrayWithObject:#"public.movie"];
// ipc.mediaTypes = [NSArray arrayWithObjects:#"public.movie", #"public.image", nil];
[self presentModalViewController:ipc animated:YES];
}
Hope will help you both code snippets.
- (IBAction) useCamera: (id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker
animated:YES];
newMedia = YES;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image, self,
#selector(image:finishedSavingWithError:contextInfo:),nil);
}
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
The Apple docs and sample code related to AVFoundation has several mistakes. See iOS 4: Take photos with live preview using AVFoundation for code that actually captures images from a live preview.

How to open camera while I click the UIButton in iPhone?

I am trying to open the camera when I click the UIbutton in iPhone app. I want to store the captured image in a location that I specify.
You need to use something like this
- (IBAction)selectPhotos
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
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];
}
- (IBAction)saveImage:(id)sender {
if(imageView.image) {
[self showProgressIndicator:#"Saving"];
UIImageWriteToSavedPhotosAlbum(imageView.image, self, #selector(finishUIImageWriteToSavedPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}
}
use [picker dismissViewControllerAnimated:YES completion:nil];
instead of [[picker parentViewController] dismissModalViewControllerAnimated:YES];
- (IBAction) useCamera: (id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker
animated:YES];
newMedia = YES;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image, self,
#selector(image:finishedSavingWithError:contextInfo:),nil);
}
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}