如何检查相机是否已打开以捕获图像或在iOS中录制视频?

时间:2014-10-17 07:33:24

标签: ios objective-c iphone

在我的应用中,应用程序允许用户捕获图像/录制视频。但我不知道如何检查以下方法的结果。

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

您的解决方案永远受到赞赏。谢谢。

1 个答案:

答案 0 :(得分:2)

这里你需要的是:

 - (void) imagePickerController: (UIImagePickerController *) picker
 didFinishPickingMediaWithInfo: (NSDictionary *) info {
    NSString *mediaType = info[UIImagePickerControllerMediaType];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        // Media is an image

        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    }
    else if ([mediaType isEqualToString:(NSString *)kUTTypeVideo] || [mediaType isEqualToString:(NSString *)kUTTypeMovie])
    {
        // Media is a video
        // Video URL
        NSURL *localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
    }
}