Application development for several versions of iOS

I am testing the application on iPhone 4 with iOS 5.1 and iPad 4 with iOS 6.0. I looked around and unexpectedly did not find similar questions:

1- My application has some methods that are deprecated in iOS 6.0, so I believe that I need to build some if / then conditions to test the system version using: [[UIDevice currentDevice] systemVersion], and then use the appropriate version of the methods. Is this the most effective way?

2. My understanding is that for one purpose, the deployment target โ€œProjectโ€ and the deployment goal โ€œGoalsโ€ serve the same purpose. And I need to have one of them or both as iOS 5.1, as this is the minimum support for iOS. What is confusing is that if the target is built on iOS 5.1, how it will work on iPad4 with iOS 6.0:

  • Does the iPad OS check the target versions before launching, or just trying to run the code, and it happens that iOS 5.1 has no code that 6.0 is not compatible with?

  • Even if this is so, but how could target 5.1 for 6.0, which I created to conditionally replace obsolete methods, be supported?

Many thanks!

+6
source share
5 answers

Deprecated Methods

Deprecated methods can be used if you target versions of iOS that were released before those methods were deprecated. But assuming that your deployment target is set correctly, you wonโ€™t get any compiler errors unless these deprecated methods are outdated for the versions you are targeting. In other words, if you see warnings in your code, you need to fix them or verify the deployment target is correct. Do not ignore them!

Xcode Installation Levels

You note the fact that you can define the deployment target at both the goal and project level. Xcode build settings at the target level override project settings. Therefore, determine the deployment target at only one of these levels, then go to the other and press delete so that you do not have duplicate values. If you have only one goal, it really doesn't matter if you define it at the goal or project level.

Backward and Forward Compatibility

Finally, there are many factors that come into play for backward and forward compatibility. Occasionally, new iOS 6 methods will appear, such as supportedInterfaceOrientations , which will simply be ignored in older versions of iOS. In other cases, you need to add explicit checks:

  • If you call a method on an object, and this method was introduced only with iOS 6, you need to add a respondsToSelector: check as follows:

     // only available on iOS 6 if ([locationManager respondsToSelector:@selector(pausesLocationUpdatesAutomatically)]) { locationManager.pausesLocationUpdatesAutomatically = YES; } 
  • If you want to check if any particular class exists in the current version of iOS, you can check the return value of the + class method as follows:

     // Only available on iOS 6 if ([UICollectionView class]) { // ... } else { // class doesn't exist in this iOS version } 
  • If you want to check if any function is available, execute a simple if statement on it:

     // Only available in iOS 6 if (ABAddressBookCreateWithOptions) { ABAddressBookCreateWithOptions(...); } else { ABAddressBookCreate(...); } 
  • Finally, if you want to check if a constant is available, check its address:

     // Only available in iOS 4 if (&UIApplicationProtectedDataDidBecomeAvailable) { // subscribe to notification } 

The basic SDK setting should always be set to "last".

If you follow all these recommendations, you can solve most of your problems without adding explicit version checks. Checking the iOS version or device ID is very fragile and can lead to the application being broken in future versions. You really want to avoid this.

+28
source
  • You can use [[UIDevice currentDevice] systemVersion] to determine the version of the OS that will work. Instead of detecting the OS version, you can use respondsToSelector: to find out what methods exist, NSClassFromString() != nil to see if classes exist, and back off if this method is not available.

  • iOS is backward compatible, so iOS 6 will launch applications for iOS 5. However, if you want to use the special feature of iOS 6, but still support iOS 5.1, you need to:

    • Compile with the 6.0 SDK so that compilers know the new APIs
    • Set the target version to the lowest supported one, aka. 5.1. Any system that exceeds this number will run the code. Anything less will not try.
    • Use one of the methods described in 1. To make sure that each device is running OS support codes.

I hope this is understandable, do not be shy if you have more questions.

+4
source

What you need to do is to discover the functionality, not the iOS version, see this topic:

Conditional support for iOS 6 features in iOS 5 app

+2
source

iOS backward compatibility. If you compile the application for iOS 5.1, it will work fine on iOS 6. There is no need to re-execute obsolete classes.

But if you change the deployment version from 5.0 to 6.0, Xcode will show you warnings if you use legacy methods

If you want to use the methods available only in iOS 6, you can use this check:

 if ([self respondsToSelector:@selector(doSomething:)]) { [self doSomething]; } 
0
source

You should not check the version of the system, but rather check the functionality that you are trying to use. On this note, remember that outdated does not mean deletion, so everything you are trying to do may very well be for iOS6. To test for specific functionality, you should do something like:

 if([TheClassInQuestion class] != nil) { //use it } 
0
source

All Articles