UIImagePickerControllerDelegate没有正确响应

时间:2010-12-06 04:02:12

标签: iphone ipad ios sdk ios4

我正在iPhone 3Gs上使用iOS 4.2.1中的UIImagePickerController。我以前使用过弃用的方法

- (void)imagePickerController: didFinishPickingImage: editingInfo:

没有问题。我在另一个应用程序中使用新的didFinishPickingMediaWithInfo API有另一个应用程序,一旦选择了媒体,该方法永远不会被选择器调用。

//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**
    }

5 个答案:

答案 0 :(得分:1)

你有

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

你可能想要的地方

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

答案 1 :(得分:0)

可能是这一行:

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

返回false。如果用户的照片库为空,则会发生这种情况;例如,在iPhone模拟器上就是如此。

编辑:正如其他示例所示,您也错误地使用了委托方法。它应该是:

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

答案 2 :(得分:0)

你有这个: - (void)imagePickerController:(UIImagePickerController *)picker imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo

看起来你重复了该方法的'imagePickerController:'部分。

答案 3 :(得分:0)

将选择器放入自动释放池可能是您的问题 - 它可能不会长时间停留以调用其委托。保留它:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

然后在代理中你可以释放它:

[picker dismissModalViewControllerAnimated:YES];
[picker release];

答案 4 :(得分:0)

这是我用来通过iOS 4.2 on 3gp>上传视频到网络服务的程序

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