问题描述
这个问题...
...收到一个答案,解释了如何测试类是否支持方法. (随着时间的流逝,Apple可能会添加该类所没有的方法,就像在旧版iOS中提供的那样.该类不是测试iOS版本,而是直接测试该类.)
...received an answer explaining how to test if a class supports a method. (Over time, Apple may have added methods that the class, as presented in an old iOS, would not have. Rather than test for the iOS version, just test the class directly.)
图书馆可以做同样的事情吗?我想继续为iOS 3.1.3构建产品,但是当用户拥有iOS 4.0(这是支持它的最早的iOS)时,我想使用CTTelephonyNetworkInfo.
Can the same thing be done for a library? I want to keep building my products for iOS 3.1.3, but I'd like to make use of CTTelephonyNetworkInfo when the users have iOS 4.0, which is the earliest iOS that supports it.
这可能吗?
推荐答案
此处的解决方案是针对仅在较新版本的iOS中可用的框架进行弱链接,然后使用NSClassFromString
和respondsToSelector:
之类的API来测试是否存在某些问题在调用之前存在.测试功能,而不是固件版本.
The solution here is to weak link against frameworks which are only available in newer versions of iOS then use APIs like NSClassFromString
and respondsToSelector:
for testing if something exists before calling it. Test for capability, not firmware version.
这篇关于如何检查iOS版本是否支持库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!