如何检查特定iOS版本上是否有可用的功能?

时间:2011-11-04 20:12:03

标签: iphone objective-c cocoa-touch uinavigationbar appearance

在我的AppDelegate中,我使用外观代理来制作自定义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];

这将在iOS4中崩溃。如何在运行的iOS版本上检查此功能是否可用,以便我可以避免崩溃?

2 个答案:

答案 0 :(得分:19)

请勿检查操作系统,检查功能是否存在。

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

答案 1 :(得分:1)

试试这个:

[UIDevice currentDevice].systemVersion