用SDK 4.2开发的iPhone应用程序,需要向后兼容iOS 3.1.3 ..简单的方法? [英] iPhone app developed with SDK 4.2, requires backward compatibility with iOS 3.1.3 .. easy way?

查看:105
本文介绍了用SDK 4.2开发的iPhone应用程序,需要向后兼容iOS 3.1.3 ..简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用SDK 4.2构建了一个iPhone应用程序但是我知道也想让它与iOS 3.1.3兼容。

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

第一步是将部署目标设置为3.1.3。它在3.2模拟器上运行正常但是应用程序有时崩溃,因为我使用的是一些早期SDK中没有的方法。

First step was to set the Deployment Target to 3.1.3. It runs fine on the 3.2 Simulator but the app crashes at times since I'm using some methods which are not available in this early SDK.

所以我的问题是,是有一种直接的方法可以找到我在项目中使用的有缺陷的方法/类,这些方法/类在3.1.3中没有提供吗? (没有手动完成每个方法调用并咨询文档以获取SDK的可用性?)

So my qestion is, is there a straight forward way to locate the offending methods/classes I'm using in my project which are not available in 3.1.3 ? (without manually going through each method call and consult with the docs for the SDK availability?)

谢谢。

UPDATE:我已经在3.1.3上执行了应用程序,并试图手动测试每个执行路径,希望找到所有异常。这完成了一定程度的成功。但是,如果应用程序是巨大的呢?并且有很多执行路径?这种情况必须有一些工具。非常感谢任何想法。

UPDATE: I have executed the app on 3.1.3 and attempted to manually test each execution path with the hope of locating all exceptions. This was completed with some level of success. However, what if the application is huge? and there are lots of execution paths? There must be some tool for this scenario. Any thoughts are much appreciated.

推荐答案

我遇到了同样的问题,只是找到了解决方案。

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

然后,下次编译应用程序时,旧版本(在本例中为iOS 3.1)中不可用的方法将被标记为已弃用且每个人都会收到警告。

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.

您可以使用 __ AVAILABILITY_INTERNAL_UNAVAILABLE 代替 __ AVAILABILITY_INTERNAL_DEPRECATED 如果你想获得错误。

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

这些行重新定义了AvailabilityInternal.h中的实际定义,所以你应该从你的前缀标题中删除它们。完成了。

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

这是ho它有效:

Apple标记头文件中方法的可用性,其中包含 __ OSX_AVAILABLE_STARTING(__ MAC_NA,__ IPHONE_4_0)等宏

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

由于您正在为iOS编译,因此应用 Availibility.h 中的以下定义:

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

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

因此这些方法实际上标有 __ AVAILABILITY_INTERNAL__IPHONE_4_0 和类似的宏。通常,当您使用新SDK进行编译时,这些宏将替换为 __ AVAILABILITY_INTERNAL_WEAK_IMPORT ,这不会产生任何警告。通过在我的前缀标题的答案开头添加行,您可以使用 __ AVAILABILITY_INTERNAL_DEPRECATED 覆盖这些定义。因此,Xcode认为这些方法已被弃用并产生警告。

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.

这篇关于用SDK 4.2开发的iPhone应用程序,需要向后兼容iOS 3.1.3 ..简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆