0

I have an iPad app that makes use in UIPrintInfo (that is being supported from iOS 4.2 and above). I want my app to run on previous iOS version such as 3.2. How can I detect in my code the device's iOS version and make the necessary changes according to the device's version?

Thanks in advance,

KingofBliss
  • 15,055
  • 6
  • 50
  • 72
jkigel
  • 1,592
  • 6
  • 28
  • 49

2 Answers2

3
Class printInfoClass = NSClassFromString(@"UIPrintInfo");

if (printInfoClass != nil )
{
id printInfo = [printInfoClass printInfo];
// Do something
}
Julio Gorgé
  • 10,056
  • 2
  • 45
  • 60
  • And printInfoClass will then be the UIPrintInfo metaclass. So you can use [[printInfo alloc] init] to get an instance of UIPrintInfo (or even [[NSClassFromString(@"UIPrintInfo") alloc] init] as a drop-in replacement for [[UIPrintInfo alloc] init], since messaging nil is safe). Just worth saying because the Smalltalk approach to metaclasses, as adopted by Objective-C, varies a bit from languages like C++. – Tommy Dec 17 '10 at 13:25
  • Thanks! How can I detect the device version? – jkigel Dec 17 '10 at 14:15
  • 2
    Don't check for the version. Instead, check for the features you care about. – Steven Fisher Dec 17 '10 at 19:02
2

Use

[[UIDevice currentDevice] systemVersion]