2012-01-06 56 views
1

我正在一个新的项目。我希望我的代码兼容IOS4和IOS5 SDK。我需要我的所有功能都可以在IOS4和IOS5中使用。也就是说,我不打算在IOS5中使用新功能(功能明智),并禁用IOS4的功能。如何使代码兼容IOS 5和IOS 4 [iphone]

我有2个选项。让我知道哪个最好?

  1. IOS4的目标和代码。而且这也可以在IOS5中正常工作,我想。
  2. BaseSDK IOS5和目标IOS4(我现在不打算使用ARC或故事板)。

我觉得用方法#2,我必须特别小心,同时使用每个用法,因为我不使用故事板和ARC,没有任何好处。所以希望#1更好。

让我知道专家意见。

注意:将来如果需要切换到IOS5的新功能,希望只有这个ARC将是阻塞,这也是一个可选的东西,我可以轻松切换rt?

回答

1

围棋与第一个。如果你正在为iOS4开发你的应用程序,并且你没有使用iOS5的新功能,那么不要让自己变得更加复杂。

想要使用第二个选项的唯一实际时间是当您想要使用iOS5中的某些新功能,但您仍然希望它在iOS4上兼容时,在这种情况下,您必须进行有条件检查对于您的程序当前正在运行的iOS版本。

顺便说一句,ARC无论如何都与iOS4兼容。

0

在工作中我们建立我们的应用程序,如选择2,当我们需要向后兼容性

5

我使用此代码来支持多个版本的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]; 
} 

希望它有帮助

+0

谢谢安舒。但这就是我的意思,关于开销或特征歧视,我不想要,因为没有为单独版本计划的特殊功能。 – mia 2012-01-06 10:38:11