iPhone app developed with SDK 4.2, requires backward compatibility with iOS 3.1.3 .. easy way?

心不动则不痛 提交于 2019-11-30 16:03:05

I had the same problem and just found a solution.

You should add the following definitions at the beginning of your prefix header:

#import <Availability.h>
#define __AVAILABILITY_INTERNAL__IPHONE_3_2 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_0 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_1 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_2 __AVAILABILITY_INTERNAL_DEPRECATED
#define __AVAILABILITY_INTERNAL__IPHONE_4_3 __AVAILABILITY_INTERNAL_DEPRECATED

Then the next time you compile the app, the methods that are not available in old versions (in this case iOS 3.1) will be marked as deprecated and you will get warnings for each of them.

You can use __AVAILABILITY_INTERNAL_UNAVAILABLE instead of __AVAILABILITY_INTERNAL_DEPRECATED if you want to get errors.

These lines redefine the actual definitions in AvailabilityInternal.h so you should remove them from your prefix header when your are done.

Here is how it works:

Apple marks the availability of the methods in the header files with macros like __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0).

Since you are compiling for iOS the following definition in Availibility.h is applied:

#define __OSX_AVAILABLE_STARTING(_mac, _iphone) __AVAILABILITY_INTERNAL##_iphone

So the methods are actually marked with __AVAILABILITY_INTERNAL__IPHONE_4_0 and similar macros. Normally when you are compiling with the new SDK these macros are replaced with __AVAILABILITY_INTERNAL_WEAK_IMPORT, which does not produce any warning. By adding the lines at the beginning of my answer to your prefix header, you overwrite these definitions with __AVAILABILITY_INTERNAL_DEPRECATED. Therefore Xcode thinks these methods are deprecated and produces the warnings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!