What should I do to adapt my app to iOS 5.0 keeping compatibility with iOS 4

后端 未结 4 719
盖世英雄少女心
盖世英雄少女心 2021-02-10 05:05

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.

Until now I\'ve overwriting drawRect: method in

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-10 06:03

    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).

    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];
    }
    

    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.

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

提交回复
热议问题