开发者

Using iPhone OS 3.0 function calls in place of deprecated 2.2 function calls on 2.2 devices

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, y开发者_运维百科ou'd call [cell setImage:image]. Will using the new [cell.imageView setImage:image] crash on 2.2 devices?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜