【发布时间】:2013-10-07 08:41:11
【问题描述】:
有一个Xcode 4.x的方法:
#define __AVAILABILITY_TOO_NEW __attribute__((deprecated("TOO NEW!"))) __attribute__((weak_import))
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
#undef __AVAILABILITY_INTERNAL__IPHONE_6_0
#define __AVAILABILITY_INTERNAL__IPHONE_6_0 __AVAILABILITY_TOO_NEW
#endif
但这不再起作用了,因为 iOS 7 SDK 可用性宏已经改变,现在有更多的变化和选项:
iOS 6 SDK 的 AvailabilityInternal.h:
#define __AVAILABILITY_INTERNAL__IPHONE_6_0 __attribute__((availability(ios,introduced=6.0)))
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_0 __attribute__((availability(ios,introduced=6.0,deprecated=6.0)))
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_1 __attribute__((availability(ios,introduced=6.0,deprecated=6.1)))
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_NA __attribute__((availability(ios,introduced=6.0)))
iOS 7 SDK:
#define __AVAILABILITY_INTERNAL__IPHONE_6_0 __attribute__((availability(ios,introduced=6.0)))
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_0 __attribute__((availability(ios,introduced=6.0,deprecated=6.0)))
#if __has_feature(attribute_availability_with_message)
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_0_MSG(_msg) __attribute__((availability(ios,introduced=6.0,deprecated=6.0,message=_msg)))
#else
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_0_MSG(_msg) __attribute__((availability(ios,introduced=6.0,deprecated=6.0)))
#endif
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_1 __attribute__((availability(ios,introduced=6.0,deprecated=6.1)))
#if __has_feature(attribute_availability_with_message)
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_1_MSG(_msg) __attribute__((availability(ios,introduced=6.0,deprecated=6.1,message=_msg)))
#else
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_6_1_MSG(_msg) __attribute__((availability(ios,introduced=6.0,deprecated=6.1)))
#endif
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_7_0 __attribute__((availability(ios,introduced=6.0,deprecated=7.0)))
#if __has_feature(attribute_availability_with_message)
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_7_0_MSG(_msg) __attribute__((availability(ios,introduced=6.0,deprecated=7.0,message=_msg)))
#else
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_7_0_MSG(_msg) __attribute__((availability(ios,introduced=6.0,deprecated=7.0)))
#endif
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_NA __attribute__((availability(ios,introduced=6.0)))
#define __AVAILABILITY_INTERNAL__IPHONE_6_0_DEP__IPHONE_NA_MSG(_msg) __attribute__((availability(ios,introduced=6.0)))
会不会是 Xcode 5 有 attribute_availability_with_message 功能,所以旧的宏重定义不再使用?
此外,打印比“太新!”更多的内容会很酷。包含所有新引入/弃用信息的消息。
编辑:
iOS 7 SDK 中的大部分定义从 __OSX_AVAILABLE_STARTING(_ios)/__AVAILABILITY_INTERNAL##_ios 移至 NS_AVAILABLE_IOS(_ios)/CF_AVAILABLE_IOS(_ios),因此重新定义:
#undef NS_AVAILABLE_IOS
#define NS_AVAILABLE_IOS(_ios) __attribute__((availability(ios,__NSi_##_ios))) __attribute__((deprecated("TOO NEW!")))
应该可以。实际上它确实如此,因为 Xcode 5 自动补全显示这些方法已弃用。
尽管打开了GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS 构建选项,但构建不会触发任何警告...
【问题讨论】:
-
有
__AVAILABILITY_INTERNAL__IPHONE_7_0吗? -
那我的回答可能会奏效。试试看。
-
有点用。请参阅编辑说明。
-
对属性尝试“不可用”而不是“已弃用”。
-
首先我知道为什么 Xcode 不会触发那些弃用警告 stackoverflow.com/questions/18197326/…。至于不可用,结果是一样的。
标签: ios objective-c api ios7 xcode5