这个问题是针对iOS版本兼容性的。
我知道如何使用respondsToSelector 检查函数是否存在(如果它是典型的Objective-C 风格方法)。即对于诸如以下的方法:
- (void) someMethod:(NSInteger)someParameter;
您可以使用:
if ([self respondsToSelector:@selector(someMethod:someParameter)]) {
//do something
}
但是 C 风格的函数呢?如何检查是否存在如下所示的函数:
void CStyleFunctionName(FoundationTypeRef parameter);
Thanks!
Xcode(至少从 4.3 开始)支持弱链接,您可以执行以下操作来查看是否可以调用 C 函数:
// UIGraphicsBeginImageContextWithOptions() was introduced in iOS 4 in order to support the Retina displays.
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(...);
}
else {
UIGraphicsBeginImageContext();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)