简体   繁体   中英

Adapt app from iOS7 to iOS6

I wrote my application for iPhone in xcode 5.0 and it supports only 7 ios.

  1. How can I make it available for ios 6?
  2. Also interested in how to prevent applications load on 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

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; 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. So suppose you write some code like this, using a class from the Sprite Kit framework, new in iOS 7:

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:

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

Sending messages to nil in Objective-C does absolutely nothing, so the above code doesn't crash. 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.

Further reading:

iOS 7 UI Transition Guide: Supporting iOS 6

Supporting Multiple iOS Versions and Devices

Second question: There is no way to say that you want your app to only run on iPhones and iPod touches. 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. You should probably think about why you don't want your app to run on iPads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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