Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a feature is available on a specific iOS version?

In my AppDelegate I am using the appearance proxy to make custom UI:

//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 can I check if this feature is available on the iOS version they are running, so I can avoid the crash?

like image 238
Sheehan Alam Avatar asked Nov 04 '11 20:11

Sheehan Alam


2 Answers

Don't check the OS, check if the capability exists.

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

like image 91
Joshua Weinberg Avatar answered Sep 28 '22 00:09

Joshua Weinberg


Try this:

[UIDevice currentDevice].systemVersion
like image 41
borisdiakur Avatar answered Sep 27 '22 22:09

borisdiakur