我应该怎么做才能使我的应用程序适应iOS 5.0,保持与iOS 4的兼容性 [英] What should I do to adapt my app to iOS 5.0 keeping compatibility with iOS 4

查看:85
本文介绍了我应该怎么做才能使我的应用程序适应iOS 5.0,保持与iOS 4的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天开始玩iOS 5了,我看到XCode 4.2只让我选择iOS 5作为Base SDK而不是iOS 4。

I've started playing with iOS 5 today and I've seen that XCode 4.2 only let me select iOS 5 as Base SDK but not iOS 4.

直到现在我覆盖了UINavigationBar中的drawRect:方法以自定义其外观,但iOS 5不再调用该方法。现在我要使用[UINavigationBar外观]来做它(我认为这要好得多)。但是,外观方法仅在iOS 5中可用,所以如果我使用它我的应用程序在iOS 4上执行时会崩溃。我该怎么办?我是否必须在每个使用iOS 5方法的地方检查带有宏的iOS版本?

Until now I've overwriting drawRect: method in UINavigationBar to customize its appearance but iOS 5 doesn't call that method anymore. Now I've to use [UINavigationBar appearance] to do it (which I think is much better). However, appearance method is only available in iOS 5 so if I use it my app it crashes when executing on iOS 4. What should I do? Do I have to check iOS version with macros in every place I use a iOS 5 method?

谢谢,

Ariel

推荐答案

您的第一个问题的答案是:您必须使用iOS5(或最新的iOS SDK)作为基础SDK ,但您在部署目标下设置了受支持的最低iOS版本。在那里你可以设置iOS4.0(或任何你想要的)。

The answer to your first question is: You must use iOS5 (or Latest iOS SDK) as your base SDK, but you set your minimum supported iOS version under Deployment Target. There you can set iOS4.0 (or whatever you want).

处理第二个问题的正确方法是测试功能 ,不是版本。所以,这样的东西可以说,你的应用程序:didFinishLaunchingWithOptions:方法:

The correct way to deal with your second question is to test for capability, not version. So, something like this would work in say, your application:didFinishLaunchingWithOptions: method:

// iOS5-only to customize the nav bar appearance
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {
    UIImage *img = [UIImage imageNamed: @"NavBarBackground.png"];
    [[UINavigationBar appearance] setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
}

然后你将针对iOS5 SDK编译这个,所以使用外观一切都会好的。但是当这个编译的代码在5之前的iOS版本上运行时,它会没问题。

You will then be compiling this against the iOS5 SDK, so the use of appearance at all will be fine. But when this compiled code runs on a version of iOS before 5, it will be fine.

如前所述,你可以保留你的 drawRect: 代码原样。

As said before, you can keep your drawRect: code as-is.

这篇关于我应该怎么做才能使我的应用程序适应iOS 5.0,保持与iOS 4的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆