Search code examples
objective-cxcodeios7gpuimage

videoMinFrameDuration is Deprecated


When I have updated Xcode from 4.6 to 5.1 `'videoMinnFrameDuration' is deprecated in ios7

- (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);

Solution

  • For one thing, you're using an outdated version of GPUImage, as this is has been fixed in the framework code for almost a year now. Update your local framework version.

    The way I address this in GPUImage, since I still need to use this method for old iOS versions, is to disable deprecation checks around the relevant code:

        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
            }
        }
    

    If the new property (activeVideoMinFrameDuration) is available, we use that. If not, it falls back to the now-deprecated method. Since we know it's deprecated, there's no need to have the compiler warn us about this.