views:

75

answers:

2

I've been asked to add a 3.0 feature (the Media Picker) to an app.

But that app must continue to run on a 2.2.1 device. (With the feature disabled)

How can I compile this, in such a way that it runs on 2.2.1, without getting a compiler error, for including a 3.0 feature?

As per the instructions in the MailComposer example, I've set my target setting to 2.2.1 and my base SDK to 3.1.2.

I've looked at weak-linking, but that is obviously just for the linker step and does nothing about compiler errors.

+3  A: 

To get around the compiler errors, just declare the C functions as extern(Objective-C functions will generate a warning, but no compiler errors). The linker errors can be fixed by weak linking, as you've disconvered.

Mike
Okay, but can I declare a type that way? Like if I need to use a pointer to a MPMediaPickerController?
Kevin Laity
For any classes used, you need to do a forward declaration. In the case for `MPMediaPickerController`, you'd do `@class MPMediaPickerController;`.
Mike
A: 

What I normally do is copy the definition of the class I need with only the methods I care about from 3.0 SDK into my project, then I call those methods as if nothing happened. The only tricky part is instantiating, for that use this:

MyCopiedClass object = [[NSClassFromString(@"MyCopiedClass") alloc] init];
DenNukem