1

在我的应用程序中,我允许用户选择是否要从库中选择照片、使用相机拍照或使用相机录制视频。

使用相机选择或拍摄照片后,点击 Use 将关闭 UIImagePickerController 并将用户带到新的 UIViewController。

当用户录制视频时,我想这样做。现在,如果用户点击“使用”按钮,它只会关闭选择器。

如何检测选择器是否设置为录制视频?

这是我尝试过的:

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
 {

     if (picker.mediaTypes == [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera] && picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo)
     {
          // Push to new view controller
          // dismiss the picker
     }

 }

是否有可能做到这一点?我应该检查什么?

谢谢!

4

2 回答 2

0

请参阅 Apple 的“iOS 相机编程主题”。那里的建议是实施imagePickerController:didFinishPickingMediaWithInfo:而不是imagePickerController:didFinishPickingImage:editingInfo:(自 iOS 3 以来已弃用)。然后,可以检查信息字典UIImagePickerControllerMediaType键的值并与适当的类型进行比较。

例如(请注意,您需要添加 MobileCoreServices 框架,并导入其标头):

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *pickedMediaType = info[UIImagePickerControllerMediaType];
    NSString *movieType = (__bridge NSString *)kUTTypeMovie;
    NSString *imageType = (__bridge NSString *)kUTTypeImage;

    if ([pickedMediaType isEqualToString:movieType]) {
        NSLog(@"movie was picked");
    }
    else if ([pickedMediaType isEqualToString:imageType]) {
        NSLog(@"image was picked");
    }
    else {
        NSLog(@"something else was picked");
    }

    [self dismissViewControllerAnimated:YES completion:nil];
}

在您的应用程序中,您将用适当的操作替换日志语句(从您的问题来看,听起来您已经有代码可以推送到新的视图控制器,因此相应地替换日志语句)。另外,请注意,您通常不应将 Objective-C 对象与==. 当我比较字符串时,我使用isEqualToString:.

于 2013-08-26T00:46:02.287 回答
0

使用下面所述的代码来检测视频的录制,并在解雇结束时将其转到 detailviewcontroller

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
[picker dismissModalViewControllerAnimated:YES];

NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];  

//not production code,  do not use hard coded string in real app
if ( [mediaType isEqualToString:@"public.image" ]) 
{                                                                                                        
    NSLog(@"Picked a photo");
}
//not production code,  do not use hard coded string in real app
else if ( [ mediaType isEqualToString:@"public.movie" ])
{
    NSLog(@"Picked a movie at URL %@",  [info objectForKey:UIImagePickerControllerMediaURL]);
    NSURL *url =  [info objectForKey:UIImagePickerControllerMediaURL];
    NSLog(@">>>>>>>>>>> Url %@", [url absoluteString]);
    RecordDetailiPhone *objDetail = [[RecordDetailiPhone alloc] initWithNibName:@"RecordDetailiPhone" bundle:nil];
    [objDetail saveVideoFileToDeractory:url];
    [self.navigationController pushViewController:objDetail animated:YES];
}
}
于 2013-08-26T05:31:39.573 回答