1

How do I write a program for iPhone (Objective C++) that runs on OS 2.0 but takes advantage of 3.0 features if they're available?

Example: copy&paste (class UIPasteboard). Nice feature to have, but I don't want to kill backward compatibility. Do I compile against SDK v. 3 or v. 2? If the latter, how do I create an instance of UIPasteboard, considering it's not declared in the headers? If the former, won't some C-linkage functions cause "unresolved reference" upon loading under OS 2.0?

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • FWIW, most iPhone devs don't consider it worthwhile to continue supporting 2.0. Very few users have stuck with it, and those who do probably aren't getting apps from the App Store. However, this issue will be more important for the 3.0-to-4.0 transition, as older iPhones won't be able to run 4.0. – Kristopher Johnson Apr 18 '10 at 18:48
  • Older iPod Touch devices don't support OS 3.0 IIRC. Worst part, there's no statistics on iTunes. :( – Seva Alekseyev Apr 18 '10 at 18:51
  • iPod Touches support 3.0, but users have to pay $15 for the upgrade. Sure, some users don't want to pay the $15, but those same users probably aren't buying too many apps. – Kristopher Johnson Apr 19 '10 at 00:07
  • This is a duplicate of http://stackoverflow.com/questions/986589/how-do-you-optionally-use-iphone-os-3-0-features-in-a-2-0-compatible-app – Brad Larson Apr 19 '10 at 13:49

2 Answers2

1

Edit your Target's build settings like this:

  • Set the Base SDK to the version whose APIs you want to use (e.g. 3.0 or 3.1).
  • Set the Deployment Target to the lowest OS version you want to support (e.g. 2.2.1).

When building, you compile against the Base SDK. For all symbols that defined in your Base SDK but not available in your Deployment Target, you need to add runtime checks to your code to check for their availability. Examples:

  1. Check if UIPasteboard is available:

    Class PasteboardClass = NSClassFromString(@"UIPasteboard");
    if (PasteboardClass != nil) {
        // UIPasteboard is available
    }
    
  2. Check if a specific method is available:

    if ([UITableViewCell respondsToSelector:@selector(initWithStyle:reuseIdentifier:)]) {
        // ...
    }
    
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
0

I didn't try this but i would recommend building against the most recent (3.x) SDK release. So you get any class and method definitions that might be available on the target device.

And in your application you have to check the OS release your application runs on. Based on the target OS you have to decide which Class and Method you should use. After all it is a big mess of conditional code, probably with a lot of additional code to provide missing functionality (i.e. direct access to SQLite instead of using Core-Data). In my experience that should not lead to problems, because most type information is erased at runtime.

Ralf Edmund
  • 1,015
  • 7
  • 10