Reputation: 383
I am on a new project. I want my code compatible to be for both IOS4 and IOS5 SDKs. I need all my functionalities work both in IOS4 and IOS5. That said, i am not planning to use new features in IOS5 (feature wise) and disable that feature for IOS4.
I have 2 options. Let me know which is best ?
I think with method #2, i have to be extra careful while using each usages at the same time as i am not using story board and ARC , there are no benefits. So hope #1 is better.
Let me know expert opinion.
Note: in future if need to switch to IOS5 new features , hope only this ARC will be the blocking and that is also an optional thing and i can easily switch rt?
Upvotes: 1
Views: 1182
Reputation: 1583
I use this code to support my app on multiple iOS versions (3.0, 4.0, 5.0) ..
put this at the top (along with imports)
#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)
then if there are some OS specific features, use them like this (I am using AlertView as an example. Pre iOS5, UIAlertView does not support a custom textView inside it, so I had my own custom AlertView. In iOS5, that hack does not work and I have to use UIAlertView as it supports custom 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];
}
Hope it helps
Upvotes: 5
Reputation: 29935
Go with the first one. If you're making your app for iOS4 and you're not using anything new from iOS5 then don't make things more complicated for yourself.
The only real time you want to use the second option is when you want to use some of the new features in iOS5 but you still want it to be compatible on iOS4, in which case you will have to put in conditional checks for the iOS version that your program is currently being run on.
By the way, ARC is compatible to iOS4 anyway.
Upvotes: 1
Reputation: 2642
At work we build our apps like Option 2 when we need backwards compatibility
Upvotes: 0