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?
Asked
Active
Viewed 670 times
0
-
Read the "SDK Compatibility Guide" in the docs. It covers this. Oh wait, that really only covers Objective-C. – rmaddy Sep 11 '14 at 15:59
-
The interoperability document discusses how to check for optional/new functionality. – David Berry Sep 11 '14 at 16:22
-
How do you create the `UIVisualEffectView`? If it's in code, show us the code. – rob mayoff Sep 14 '14 at 01:59
2 Answers
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