为 iPhone 模拟器 3.0 构建时,imagepicker 控制器显示错误

发布于 2024-08-17 16:40:59 字数 1687 浏览 4 评论 0原文

我正在开发一个同时使用视频录制和照片拍摄的应用程序。因此,我想根据操作系统显示按钮,为此我实现了这些方法。当我为 OS 3.1 构建时,它工作正常,但当我为 OS 3.0 构建时,它会

在此处 方法

    if ([self videoRecordingAvailable])
    {
        imagePickerController.sourceType =  UIImagePickerControllerSourceTypeCamera;
        imagePickerController.allowsImageEditing = YES;
        imagePickerController.allowsEditing = YES;
        imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
        imagePickerController.videoMaximumDuration = 60.0f; // Length for video recording in seconds
        imagePickerController.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];
        imagePickerController.showsCameraControls=YES;      
        [self.navigationController presentModalViewController:imagePickerController animated:YES];          
    }


- (BOOL) videoRecordingAvailable
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) return NO;
return [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera] containsObject:@"public.movie"];
}

显示错误错误的

error: request for member 'allowsEditing' in something not a structure or union
error: request for member 'videoQuality' in something not a structure or union
error: 'UIImagePickerControllerQualityTypeHigh' undeclared (first use in this function)
 (Each undeclared identifier is reported only once for each function it appears in.)
error: request for member 'videoMaximumDuration' in something not a structure or union
error: request for member 'showsCameraControls' in something not a structure or union

是什么,我该如何解决这个问题?

I am developing an application which uses both video recording and photo shoting.So i want to show buttons according to os for this i implement these methods.It's working fine when i build for OS 3.1 but when i build for OS 3.0 it shows errors

here are the methods

    if ([self videoRecordingAvailable])
    {
        imagePickerController.sourceType =  UIImagePickerControllerSourceTypeCamera;
        imagePickerController.allowsImageEditing = YES;
        imagePickerController.allowsEditing = YES;
        imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
        imagePickerController.videoMaximumDuration = 60.0f; // Length for video recording in seconds
        imagePickerController.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];
        imagePickerController.showsCameraControls=YES;      
        [self.navigationController presentModalViewController:imagePickerController animated:YES];          
    }


- (BOOL) videoRecordingAvailable
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) return NO;
return [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera] containsObject:@"public.movie"];
}

the errors are

error: request for member 'allowsEditing' in something not a structure or union
error: request for member 'videoQuality' in something not a structure or union
error: 'UIImagePickerControllerQualityTypeHigh' undeclared (first use in this function)
 (Each undeclared identifier is reported only once for each function it appears in.)
error: request for member 'videoMaximumDuration' in something not a structure or union
error: request for member 'showsCameraControls' in something not a structure or union

how do i solve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卸妝后依然美 2024-08-24 16:40:59

问题在于3.1中添加了视频捕获,这意味着3.0中的图像选择器不支持任何视频属性和方法(请参阅文档 并注意可用性部分)。

至于解决方案,我想你可以尝试使用消息语法而不是点语法:

[picker setShowsCameraControls:YES];

但这会给你警告(当为 3.0 及更早版本编译时),并且你必须小心不要在旧设备上执行此操作,因为你会得到一个未知的选择器异常。或者您可以动态调用选择器,这将消除警告,您还可以首先检查选择器是否受支持:

SEL msg = @selector(setShowsCameraControls:);
if ([picker respondsToSelector:msg])
    [picker performSelector…];

已经有 几个< /a> 有关针对不同操作系统版本编写的问题


回复评论:我认为主要问题是您在不理解代码的情况下盲目粘贴代码。不要那样做。坐下来思考代码的作用,直到理解每一行。现在更彻底地解释您的问题:

3.0 中的图像选择器没有视频控件,因为它无法录制视频。因此,当您尝试编译诸如 picker.showsCameraControls 之类的代码时,编译器会抱怨: Image Picker 类中没有 showsCameraControls 属性,该属性仅在 3.1 中添加。

但有一种解决方法,您可以使用消息语法 ([foo setBar:...]) 而不是点语法 (foo.bar=...)。如果 foo 对象没有 setBar 方法,编译器会警告您,但代码会编译。现在让我们使用消息语法来设置相机控制:

[picker setShowsCameraControls:YES];

当您为 3.1 编译此代码时,它将在没有警告的情况下进行编译,并且运行时不会出现错误。当您编译 3.0 时,您将从编译器收到警告,如果运行代码,它将失败(因为实际上没有 showsCameraControls 属性)。但这不是问题,因为您只能决定在操作系统支持的情况下运行脆弱的代码:

BOOL videoSupported = [picker respondsToSelector:@selector(setShowsCameraControls:)];
if (videoSupported) {
    [picker setShowsCameraControls:YES];
    // set all the other video properties
} else {
    // do what makes sense without video support
}

这会起作用,但您仍然会在 3.0 上收到编译器警告。现在它取决于您的默认构建目标。如果您针对 3.1 进行构建,则警告将会消失,并且代码应该可以在 3.0 上正常运行。

The problem is that the video capture has been added in 3.1, which means that the image picker from 3.0 does not support any of the video properties and methods (see the documentation and pay attention to the Availability sections).

As for the solution, I guess you could try using the message syntax instead of the dot syntax:

[picker setShowsCameraControls:YES];

This will give you warnings though (when compiled for 3.0 and older), and you have to be careful not to do it on older devices, because you’ll get an unknown selector exception. Or you can call the selector dynamically, which will get rid of the warnings and you can also check if the selector is supported first:

SEL msg = @selector(setShowsCameraControls:);
if ([picker respondsToSelector:msg])
    [picker performSelector…];

There are already several questions about writing for different OS versions.


Responding to comments: I think the main problem is that you are blindly pasting the code without understading it. Don’t do that. Sit and think about what the code does, until you understand each and every line. Now to explain your problem more thoroughly:

The Image Picker in 3.0 has no video controls, since it can’t record video. Therefore when you try to compile a code such as picker.showsCameraControls, the compiler complains: There is no showsCameraControls property in the Image Picker class, that has only been added in 3.1.

But there is a way around that, you can use the message syntax ([foo setBar:…]) instead of the dot syntax (foo.bar=…). If the foo object has no setBar method, the compiler will warn you, but the code will compile. Now let’s use the message syntax to set the camera controls:

[picker setShowsCameraControls:YES];

When you compile this code for 3.1, it will compile without warning and run without error. When you compile for 3.0, you will get a warning from the compiler and if you run the code, it will fail (since there really is no showsCameraControls property). But that is not a problem, since you can only decide to run the fragile code if the OS supports it:

BOOL videoSupported = [picker respondsToSelector:@selector(setShowsCameraControls:)];
if (videoSupported) {
    [picker setShowsCameraControls:YES];
    // set all the other video properties
} else {
    // do what makes sense without video support
}

This will work, but you’ll still get compiler warnings on 3.0. Now it depends on your default build target. If you build for 3.1, the warnings will disappear and the code should work on 3.0 just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文