Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c imagepicker控制器在为iphone simulator 3.0构建时显示错误_Objective C_Xcode_Iphone Sdk 3.0_Uiimagepickercontroller - Fatal编程技术网

Objective c imagepicker控制器在为iphone simulator 3.0构建时显示错误

Objective c imagepicker控制器在为iphone simulator 3.0构建时显示错误,objective-c,xcode,iphone-sdk-3.0,uiimagepickercontroller,Objective C,Xcode,Iphone Sdk 3.0,Uiimagepickercontroller,我正在开发一个同时使用视频录制和照片拍摄的应用程序。因此,我想根据操作系统显示按钮。为此,我实现了这些方法。当我为操作系统3.1构建时,它工作正常,但当我为操作系统3.0构建时,它会显示错误 以下是方法 if ([self videoRecordingAvailable]) { imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; imagePick

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

如何解决此问题?

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

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

[picker setShowsCameraControls:YES];
不过,这会给您带来警告(在为3.0及更高版本编译时),您必须小心不要在较旧的设备上执行此操作,因为您会遇到未知的选择器异常。或者,您可以动态调用选择器,这将消除警告,您还可以先检查选择器是否受支持:

SEL msg = @selector(setShowsCameraControls:);
if ([picker respondsToSelector:msg])
    [picker performSelector…];
已经有很多关于编写不同操作系统版本的文章


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

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

但是有一种解决方法,您可以使用消息语法(
[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上正常工作。

不,因为我真诚地认为您最好现在自己解决它。至少在你再次遇到真正的问题之前。但它不起作用;SEL msg=@选择器(setVideoQuality:);if([imagePickerController响应选择器:msg])[imagePickerController执行选择器:msg with object:self afterDelay:0];但它仍然显示错误实际上我不知道如何设置值…这行[picker performSelector…]的意思是什么;如何设置此[imagePickerController设置视频质量:UIImagePickerController质量类型高];现在它显示了警告。但setVideoQuality上仍然存在错误…请告诉我performselector的使用情况…我猜这是因为您缺少
UIImagePickerControllerQualityTypeHigh
常量。您可以尝试将其替换为零。这是一个黑客,但我认为它会为你的目的。