使用 SDK 4.2 开发的 iPhone 应用程序,需要向后兼容 iOS 3.1.3 ..简单的方法吗?
我已经使用 SDK 4.2 构建了一个 iPhone 应用程序,但我知道还想让它与 iOS 3.1.3 兼容。
第一步是将部署目标设置为 3.1.3。它在 3.2 模拟器上运行良好,但应用程序有时会崩溃,因为我使用了一些早期 SDK 中不可用的方法。
所以我的问题是,是否有一种直接的方法来定位我在项目中使用的 3.1.3 中不可用的违规方法/类? (无需手动检查每个方法调用并查阅文档以了解 SDK 的可用性?)
谢谢。
更新:我已在 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.
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.
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?)
Thanks.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,刚刚找到了解决方案。
您应该在前缀标头的开头添加以下定义:
然后,下次编译应用程序时,旧版本(在本例中为 iOS 3.1)中不可用的方法将被标记为已弃用,并且您将收到警告他们每个人。
如果您想收到错误,可以使用
__AVAILABILITY_INTERNAL_UNAVAILABLE
而不是__AVAILABILITY_INTERNAL_DEPRECATED
。这些行重新定义了 AvailabilityInternal.h 中的实际定义,因此您应该在完成后从前缀标头中删除它们。
其工作原理如下:
Apple 使用
__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0)
等宏在头文件中标记方法的可用性。由于您正在针对 iOS 进行编译,因此将应用
Availibility.h
中的以下定义:因此这些方法实际上是用
__AVAILABILITY_INTERNAL__IPHONE_4_0
和类似的宏进行标记的。通常,当您使用新的 SDK 进行编译时,这些宏会替换为 __AVAILABILITY_INTERNAL_WEAK_IMPORT,这不会产生任何警告。通过将我的答案开头的行添加到您的前缀标头中,您可以使用__AVAILABILITY_INTERNAL_DEPRECATED
覆盖这些定义。因此 Xcode 认为这些方法已被弃用并产生警告。I had the same problem and just found a solution.
You should add the following definitions at the beginning of your prefix header:
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: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.