well to begin with I'm sure this is a simple question.
I am developing an iPhone app with the iAd Framework, which only runs for iOS 4.0 or higher.
Still, I wanna choose a iPhone OS 3.0 deployment target, which causes everything to crash.
- How do I conditionally include the iAd framework? ...I mean, it would be something like: ...if([[UIDevice currentDevice] systemVersion]>=4.0]) #import
Obviously this won't work because I don't know the correct syntax. Also:
- How do I conditionally declare an AdView* variable?
- How do I conditionally handle this AdView* variable in my implementation file.
If you guys could help me, I will be very well impressed.
Thanks
You don't need to change your include, you need to make the iAd (or any other new framework) linked weakly:
In your target, find iAd in the linked frameworks and change its "Role" from "Required" to "Weak".
To handle the variable conditionally, use
NSClassFromString
function, like this:If OS is older than iOS 4.0,
AdClass
will benil
and the code won't execute. Note that usingADBannerView*
as the type of the variable shouldn't cause any problems, as it's just a hint for a compiler and is the same asid
after compilation.