0

I am making a game, and I didnt realise that I set the targeted device as iOS 8. I went to change it to iOS 7 so that it is compatible with more devices. However, as tested on iOS 7, I realised that the UIVisualEffectView does not work. Is there anyway I can have the UIVisualEffectView to only appear when the running device has iOS 8 and not iOS 7?

user2397282
  • 3,798
  • 15
  • 48
  • 94

2 Answers2

2

You can check for UIVisualEffectView being available like this:

if (NSClassFromString("UIVisualEffectView") != nil) {
    NSLog("UIViewVisualEffectView is available");
    // Use UIVisualEffectView
} else {
    NSLog("UIViewVisualEffectView is not available");
    // Do something else
}

This approach is nice because the code documents why the if statement is being used, and you don't have to remember the OS version when a class was introduced.

MaxGabriel
  • 7,617
  • 4
  • 35
  • 82
0

Check out this thread. You can get the current iOS version using one of the macros in this answer, then decide which classes to use. For example:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
    // Use UIVisualEffectViewClass
} else {
    // Use another class
}

If you're using swift, ignore the macro part, and just use the code.

Community
  • 1
  • 1
michaelsnowden
  • 6,031
  • 2
  • 38
  • 83