我使用此代碼來支持多個版本的iOS(3.0,4.0,5.0),我的應用程序..
把這個頂部(連同進口)
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
然後,如果有一些操作系統特定的功能,像這樣使用它們(我使用AlertView作爲示例,在iOS5之前,UIAlertView不支持自定義的textView,所以我有自己的自定義AlertView在iOS5中,這種黑客行不通,我有使用UIAlertView,因爲它支持自定義textViews):
if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
TextAlertView *alert = [[TextAlertView alloc] initWithTitle:@"xxxYYzz"
message:@""
delegate:self cancelButtonTitle:@"Add"
otherButtonTitles:@"Cancel", nil];
alert.textField.keyboardType = UIKeyboardTypeDefault;
alert.tag = 1;
self.recipeNameTextField = alert.textField;
[alert show];
[alert release];
}
else {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"xxYYzz"
message:@""
delegate:self cancelButtonTitle:@"Add"
otherButtonTitles:@"Cancel", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
self.recipeNameTextField = [alert textFieldAtIndex:0];
[alert show];
[alert release];
}
希望它有幫助
謝謝安舒。但這就是我的意思,關於開銷或特徵歧視,我不想要,因爲沒有爲單獨版本計劃的特殊功能。 – mia 2012-01-06 10:38:11