开发者

UIImagePickerControllerDelegate not responding properly

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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜