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

前端 未结 1 910
不知归路
不知归路 2021-01-03 10:02

I have built an iPhone app with SDK 4.2 however I know also want to make it compatible with iOS 3.1.3.

First step was to set the Deployment Target to 3.1.3. It runs

相关标签:
1条回答
  • 2021-01-03 10:29

    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.

    0 讨论(0)
提交回复
热议问题