How to check if a feature is available in a specific version of iOS?

In my AppDelegate application, I use an appearance proxy to create a user interface:

//Setup custom appearances [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"header"] forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setTintColor:[UIColor blackColor]]; [[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"header"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault]; 

This will crash in iOS4. How to check if this feature is available in the iOS version that they run, so I can avoid the crash?

+6
source share
2 answers

Do not check the OS, check if there is a possibility.

if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {}

+19
source

Try the following:

 [UIDevice currentDevice].systemVersion 
+1
source

Source: https://habr.com/ru/post/900816/


All Articles