views:

466

answers:

2

If I set the Base + Active SDK of an iPhone app to 3.0 and the Deployment Target to 2.2, can I use the new versions of functions on 2.2 devices?

For example, UITableViewCell now requires an image to be set using [cell.imageView setImage:image], whereas in 2.2, you'd call [cell setImage:image]. Will using the new [cell.imageView setImage:image] crash on 2.2 devices?

+1  A: 

No, you cannot use OS 3.0 calls on a 2.x device. I'd be surprised if you can even install a 3.0-targeted app on a 2.x device.

Ben Gottlieb
Hi,I think you misread - the Deployment Target is set to 2.2 (as per the Apple best practices).
Ted
There are a couple things at play here: the BASE SDK, the Deploy target, and the ACTIVE SDK. You can set the BASE SDK to whatever you want, however, API calls that are specific to (for example) the 3.0 SDK won't be available (ie. won't compile) until the ACTIVE SDK is set to 3.0 or later. The deploy target will let you install a 3.0-active-SDK on a 2.x target, but it will not run.
Ben Gottlieb
So I'd get a crash at runtime when calling `[cell.imageView setImage:image]` on 2.2?
Ted
yes, you would crash.
Ben Gottlieb
+3  A: 

Nope you cannot us OS 3.0 calls on 2.2. Deprecated method should be behave as normal at least in OS 3. Deprecation in many cases in the OS, just means that Apple recommend using new methods rather then deprecated ones; but those methods may disappear in the future too.

You have few options:

  1. Simply ignoring the warnings, as long as app and methods actually work on OS 3.0.
  2. Have a runtime check to determine the OS version, and invoke the appropriate method:

    double version = [[[UIDevice currentDevice] systemVersion] doubleValue];
    if (version >= 3.0) {
        [cell.imageView setImage:image];
    } else {
        [cell setImage:image];
    }
    

    or better yet:

    if ([cell respondsToSelector:@selector(imageView)]) {
         [cell.imageView setImage:image];
    } else {
         [cell setImage:image];
    }
    

    Note that a compile time check, using ifdef directives won't work

  3. Dropping OS 2.2 support. It's quite reasonable for you to only target 3.0 as well, as the uptake of 3.X is quite high. In the case of my small app, in December I had 27 users on pre-3.0 systems out of 2,058 users. Needless to say, this option reduces your testing need significantly.

notnoop
Fair enough - I was hoping the system would sort out the new function calls at compile-time when the Deployment Target was appropriately set.Personally, I'd prefer using `if([cell respondsToSelector:@selector(imageView)])` as my runtime check, but I'm sure that's a matter of preference ;)
Ted
i added your suggestion. respondsToSelector is for sure better than OS check on my opinion too, just forgot about it! Objective-C is a dynamic language so methods don't get resolved at compile time.
notnoop
Nice one. I'm still curious, though - would `[cell.imageView setImage:image]` just have crashed at runtime on 2.2? Unfortunately, I don't have a 2.2 device to test on.
Ted
Yes, cell.imageView would crash at runtime (it wouldn't even get to the setImage part.
Ben Gottlieb
Yes, it would crash. If you don't have a 2.2 device, you shouldn't target it then. You should test your apps significantly before pushing them. The simulator helps a bit, as you can change the SDK version as well.
notnoop
Good to know :) By the way, 2.2 is still fairly prevalent on iPod Touches, due to the cost of upgrading - hence, retaining support for it can be important for certain types of apps (particularly those targeting younger audiences).
Ted