3

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**
    }
Andy Obusek
  • 12,614
  • 4
  • 41
  • 62
akaru
  • 6,299
  • 9
  • 63
  • 102
  • is that code block getting called? by which I mean -- does `[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]` return `YES`? – Sam Ritchie Dec 06 '10 at 04:09

5 Answers5

1

you have

- (void)imagePickerController:(UIImagePickerController *)picker imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo

where you probably want

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
tmiddlet
  • 296
  • 1
  • 3
0

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
Sam Ritchie
  • 10,988
  • 4
  • 42
  • 53
0

You have this: - (void)imagePickerController:(UIImagePickerController *)picker imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo

Look like you repeated the 'imagePickerController:' part of that method.

Firoze Lafeer
  • 17,133
  • 4
  • 54
  • 48
0

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];
Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
0

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];
}
Andy Obusek
  • 12,614
  • 4
  • 41
  • 62
GhostRider
  • 1,197
  • 10
  • 19