Search code examples
iphoneobjective-ccocoa-touchuinavigationbarappearance

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?


Solution

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

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