Search code examples
iosswiftipad-2cifilter

Why am I getting an "unrecognized selector sent to class" error for CIFilter?


This code works on an iPad 2 simulator, but not on my physical iPad 2 (which is running on iOS 7.0.6):

var fade = CIFilter(name: "CIExposureAdjust", withInputParameters:["inputEV" : -2.0 ])

The full error message says:

[CIFilter filterWithName:withInputParameters:]: unrecognized selector sent to class 0x392d8d9c 2015-07-05 23:12:37.106 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[CIFilter filterWithName:withInputParameters:]: unrecognized selector sent to class 0x392d8d9c'


Solution

  • Check the official documentation of + filterWithName:withInputParameters:

    + filterWithName:withInputParameters:

    Availability
    Available in iOS 8.0 and later.

    Since your iPad is running on iOS 7, this method is not available, and therefore your app crashes.

    A few possible solutions:

    1. Use - respondsToSelector: to check if the method exists.

    2. Check if the current foundation version number, NSFoundationVersionNumber is higher than NSFoundationVersionNumber_iOS_7_1.

    3. Make iOS 8 a minimum requirement for your app.