2014-07-07 289 views
2

当我从4.6到5.1'“videoMinnFrameDuration” Xcode更新在ios7videoMinFrameDuration已被弃用

- (void)setFrameRate:(NSInteger)frameRate; 
{ 
_frameRate = frameRate; 

if (_frameRate > 0) 
{ 
    for (AVCaptureConnection *connection in videoOutput.connections) 
    { 

     if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)]) 
      connection.videoMinFrameDuration = CMTimeMake(1,_frameRate); 
+0

已弃用的方法意味着它由于安全问题已过时,因为新方法执行相同的事情或任何其他原因。它仅包含在运行旧版xcode的设备中,仍然可以运行你的代码。为了代码安全和便携性的目的,你不应该再使用它了。请参阅文档以了解替代使用哪种方法。 – Aserre

回答

5

一件事,你使用GPUImage过时的版本,因为这是一直固定在框架代码将近一年了。更新您的本地框架版本。

我解决这个问题的GPUImage,因为我还需要使用此方法用于旧的iOS版本的方式,是禁用围绕相关代码弃用检查:

if ([_inputCamera respondsToSelector:@selector(setActiveVideoMinFrameDuration:)] && 
     [_inputCamera respondsToSelector:@selector(setActiveVideoMaxFrameDuration:)]) { 

     NSError *error; 
     [_inputCamera lockForConfiguration:&error]; 
     if (error == nil) { 
#if defined(__IPHONE_7_0) 
      [_inputCamera setActiveVideoMinFrameDuration:CMTimeMake(1, _frameRate)]; 
      [_inputCamera setActiveVideoMaxFrameDuration:CMTimeMake(1, _frameRate)]; 
#endif 
     } 
     [_inputCamera unlockForConfiguration]; 

    } else { 

     for (AVCaptureConnection *connection in videoOutput.connections) 
     { 
#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Wdeprecated-declarations" 
      if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)]) 
       connection.videoMinFrameDuration = CMTimeMake(1, _frameRate); 

      if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)]) 
       connection.videoMaxFrameDuration = CMTimeMake(1, _frameRate); 
#pragma clang diagnostic pop 
     } 
    } 

如果新的属性(activeVideoMinFrameDuration)是可用,我们使用它。如果不是,则回退到现在已弃用的方法。由于我们知道它已被弃用,所以没有必要让编译器警告我们这一点。

+0

非常感谢 –

0

弃用AVCaptureSession.h类AVFoundation它由以下注释提及。

@property supportsVideoMinFrameDuration 
@abstract 
    Indicates whether the connection supports setting the videoMinFrameDuration property. 

@discussion 
    This property is only applicable to AVCaptureConnection instances involving 
    video. In such connections, the videoMinFrameDuration property may only be set if 
    -isVideoMinFrameDurationSupported returns YES. 

    This property is deprecated on iOS, where min and max frame rate adjustments are applied 
    exclusively at the AVCaptureDevice using the activeVideoMinFrameDuration and activeVideoMaxFrameDuration 
    properties. On Mac OS X, frame rate adjustments are supported both at the AVCaptureDevice 
    and at AVCaptureConnection, enabling connections to output different frame rates.