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.
source share