Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I do to adapt my app to iOS 5.0 keeping compatibility with 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.

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?

Thank you,

Ariel

like image 548
arielcamus Avatar asked Oct 14 '11 19:10

arielcamus


People also ask

How do I make an app compatible with an older version of iOS?

Download an older app version:Go to the Purchased screen. For iPhone the Purchase screen is in the Updates tab. Select the app you want to download. If a compatible version of the app is available for your version of iOS simply confirm that you want to download it.

How do you install apps that are not compatible with your device iOS?

Open iTunes and select Apps from the drop-down menu. Then click the App Store button and search for the app you want to download. Click to download the app, which may prompt you to enter your Apple ID password. The App Store in iTunes has all the same apps that you find on other devices.

How do I see incompatible apps on iOS?

If you want to check which of your existing apps aren't compatible with iOS 11, go to Settings > General > About > Applications and there will be a list of those that aren't going to survive the transition.


1 Answers

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.

like image 87
Mark Granoff Avatar answered Nov 14 '22 22:11

Mark Granoff