Since the launch of IOS 5, I have had to make some changes to my app that only apply when IOS 5 is being used. How can I tell when launching my app whther the user is using IOS 5 or IOS 4 or earlier?
if([[[UIDevice currentDevice] systemVersion] compare:@"5.0" options:NSNumericSearch] != NSOrderedDescending)
{
// code here
}
else
{
// code here
}
You should probably avoid asking about the system version altogether.
A better design would ask about a specific feature.
For instance: if (NSClassFromString(@"UIPrintInfo"))
would tell you if the current device supports the printing API,available in 4.2 or higher.
That way you can plan your code to use a feature if it's available, on not based on the OS version. More on this here - How to check iOS version?
But if you must then -
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
Sometime is nice to know which version of iOS is used. But it is better to ask the system if a method exist:
// iOS 5 UINavigationBar backgroundImage
if ([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
UIImage *backgroundImage = [UIImage imageNamed:@"titlebar.png"];
[self.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.