简体   繁体   English

将应用程序从iOS7适配到iOS6

[英]Adapt app from iOS7 to iOS6

I wrote my application for iPhone in xcode 5.0 and it supports only 7 ios. 我用xcode 5.0编写了iPhone应用程序,它仅支持7个ios。

  1. How can I make it available for ios 6? 如何使它可用于ios 6?
  2. Also interested in how to prevent applications load on ipad? 还对如何防止ipad上的应用程序加载感兴趣?

First question: Make sure your deployment target is 6.0, don't use API's that are iOS 7 only, or check by using 第一个问题:确保您的部署目标是6.0,请勿使用仅适用于iOS 7的API,或者使用

if ([someObject respondsToSelector:@selector(ios7onlymethod)] {
    // do your iOS 7 only stuff
} else {
    // Fall back to iOS 6-supported ways
}

Or use 或使用

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
    // do your iOS 7 only stuff
} else {
    // Fall back to iOS 6-supported ways
}

New frameworks you want to use should be marked as optional in Xcode; 您要使用的新框架应在Xcode中标记为可选; to do that select your target, click general, and scroll to the "Linked Frameworks and Libraries" section. 为此,请选择目标,单击常规,然后滚动到“链接的框架和库”部分。

可选框架

What's really cool is that classes in frameworks marked as optional are replaced with nil on versions of iOS that don't have them. 真正很酷的是,在没有它们的iOS版本上,标记为可选的框架中的类被替换为nil So suppose you write some code like this, using a class from the Sprite Kit framework, new in iOS 7: 因此,假设您使用iOS 7中新增的Sprite Kit框架中的类编写了如下代码:

SKSpriteNode *spriteNode = [SKSpriteNode spriteWithImageNamed:@"mySprite"];

On iOS 6, when the linker, which "links" frameworks to apps (apps don't copy frameworks, they just get them from the system), sees SKSpriteNode in your code, and the framework is marked as optional, that line of code will be replaced by this: 在iOS 6上,当链接程序将框架“链接”到应用程序(应用程序不复制框架,它们只是从系统获取框架)时, SKSpriteNode在您的代码中看到SKSpriteNode ,并且该框架被标记为可选,该行代码将被替换为:

... = [nil spriteWithImageNamed:@"mySprite"];

Sending messages to nil in Objective-C does absolutely nothing, so the above code doesn't crash. 在Objective-C中将消息发送到nil绝对没有任何作用,因此上面的代码不会崩溃。 No problem. 没问题。 So instead of lingering your code with if -statements checking for the existence of a class, you can just go with the flow and let the dynamic linker do the work. 因此,您可以使用流程并让动态链接器完成工作,而不是通过if -statements检查代码if存在来挥霍代码。

Further reading: 进一步阅读:

iOS 7 UI Transition Guide: Supporting iOS 6 iOS 7 UI过渡指南:支持iOS 6

Supporting Multiple iOS Versions and Devices 支持多种iOS版本和设备

Second question: There is no way to say that you want your app to only run on iPhones and iPod touches. 第二个问题:不能说您希望您的应用仅在iPhone和iPod touch上运行。 You can require things that are specifical to the iPhone and iPod touch (like a certain processor architecture or the M7 motion coprocessor) but Apple won't like it if you require the M7 chip to exclude a certain device when you don't even need it. 您可能需要特定于iPhone和iPod touch的功能(例如某些处理器体系结构或M7运动协处理器),但是如果您需要M7芯片甚至不需要时就排除某些设备,Apple不会喜欢它。它。 You should probably think about why you don't want your app to run on iPads. 您可能应该考虑为什么不希望您的应用程序在iPad上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM