我在 xcode 5.0 中编写了 iPhone 应用程序,它仅支持 7 个 ios。
- 如何使其适用于 iOS 6?
- 还对如何防止应用程序在 iPad 上加载感兴趣?
最佳答案
第一个问题:确保您的部署目标是 6.0,不要使用仅限 iOS 7 的 API,或者使用进行检查
if ([someObject respondsToSelector:@selector(ios7onlymethod)] {
// do your iOS 7 only stuff
} else {
// Fall back to iOS 6-supported ways
}
或者使用
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
// do your iOS 7 only stuff
} else {
// Fall back to iOS 6-supported ways
}
您想要使用的新框架应在 Xcode 中标记为可选;为此,请选择您的目标,单击“常规”,然后滚动到“链接的框架和库”部分。
真正酷的是,框架中标记为可选的类在没有这些类的 iOS 版本上被替换为 nil
。因此,假设您使用 Sprite Kit 框架(iOS 7 中的新增功能)中的类编写了如下代码:
SKSpriteNode *spriteNode = [SKSpriteNode spriteWithImageNamed:@"mySprite"];
在 iOS 6 上,当链接器将框架“链接”到应用程序(应用程序不会复制框架,它们只是从系统获取框架)时,会在代码中看到 SKSpriteNode
,并且框架被标记为可选,该行代码将被替换为:
... = [nil spriteWithImageNamed:@"mySprite"];
在 Objective-C 中向 nil 发送消息绝对不会执行任何操作,因此上面的代码不会崩溃。没问题。因此,您不必在代码中使用 if
语句来检查类是否存在,而是可以顺其自然,让动态链接器完成工作。
进一步阅读:
iOS 7 UI Transition Guide: Supporting iOS 6
Supporting Multiple iOS Versions and Devices
第二个问题:没有办法说您希望您的应用仅在 iPhone 和 iPod touch 上运行。您可以要求 iPhone 和 iPod touch 特有的东西(例如特定的处理器架构或 M7 运动协处理器),但如果您需要 M7 芯片来排除某个您根本不需要的设备,Apple 不会喜欢它它。您可能应该考虑一下为什么不希望您的应用在 iPad 上运行。
关于iphone - 将应用程序从 iOS 7 适配到 iOS 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20305605/