iPhone的正常降级 [英] Graceful degradation on iPhone

查看:65
本文介绍了iPhone的正常降级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何编写适用于iPhone 2.0的程序(Objective C ++),该程序可以在OS 2.0上运行,但可以利用3.0功能?

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?

示例:复制并粘贴(UIPasteboard类).不错的功能,但我不想终止向后兼容性.是否可以针对SDK v.3或v.2进行编译?如果是后者,考虑到标头中未声明该实例,如何创建UIPasteboard实例?如果是前者,在OS 2.0下加载时,某些C链接功能是否不会导致未解析的引用"?

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?

推荐答案

编辑目标的构建设置,如下所示:

Edit your Target's build settings like this:

  • 将基本SDK设置为要使用其API的版本(例如3.0或3.1).
  • 将部署目标"设置为要支持的最低操作系统版本(例如2.2.1).

在构建时,您将根据Base SDK进行编译.对于在Base SDK中定义但在Deployment Target中不可用的所有符号,您需要在代码中添加运行时检查以检查其可用性.例子:

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. 检查UIPasteboard是否可用:

  1. Check if UIPasteboard is available:

Class PasteboardClass = NSClassFromString(@"UIPasteboard");
if (PasteboardClass != nil) {
    // UIPasteboard is available
}

  • 检查特定方法是否可用:

  • Check if a specific method is available:

    if ([UITableViewCell respondsToSelector:@selector(initWithStyle:reuseIdentifier:)]) {
        // ...
    }
    

  • 这篇关于iPhone的正常降级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆