I am developing a universal app which is built using SDK 4.2 and expected to work on 3.1 to 4.2 devices. UIPopOverController is used in my code. there are few references which is common to both iphone and ipad. Is there a way to make the ios 3.1 to convince,
"Don't include this xyz.h if it is 3.1 device". Is there a开发者_C百科ny pre-processor which make the 3.1. os to accept this statement ?
The compiler doesn't compile an app for each device version. So you can't just "exclude" xyz.h for 3.1 devices. You can however check if classes are available.
Class popoverClass = NSClassFromString(@"UIPopoverController");
if(popoverClass) {
// class is available
UIPopoverController *popover = ...
}
else {
// use alternate method
[self presentModalViewController:vc animated:YES];
}
or you can apply a different logic to iphone or ipad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// do something that will only be done on ipad
}
else {
// do something that will only be done on iphone
}
if you want to use classes that are generally available in lower firmware versions but specific methods might be unavailable you have to check before using them.
NSURL *fileURL = nil;
if ([NSURL respondsToSelector:@selector(fileURLWithPathComponents:)]) {
fileURL = [NSURL fileURLWithPathComponents:...];
}
else {
/* another method to create fileURL */
fileURL = ...;
}
note that all this happens on runtime.
There is no harm in linking symbols that don't exist in 3.1. Your goal is to make sure those symbols won't be referenced during execution flow on 3.1 devices.
精彩评论