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 开发工具包:
#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
但是,尽管打开了构建选项,但构建不会触发任何警告...