即使class不可用,NSClassFromString()也会返回一个类 [英] NSClassFromString() returns a class even when class should not be available

查看:90
本文介绍了即使class不可用,NSClassFromString()也会返回一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用iOS 4.0在iPhone 3G上测试应用程序。

I am currently testing an app on an iPhone 3G with iOS 4.0.

我有以下代码来检查此类是否可用。

I have the following code to check if this Class is available.

if (NSClassFromString(@"CLGeocoder"))

在文档中,它声明CLGeocoder可用于iOs 5.0及更高版本。
但上面的代码不会返回nil。

In the documentation it states that CLGeocoder is available for iOs 5.0 and later. But the code above does not return nil.

为什么?这个类不应该在iOS 4.0中可用

Why? this Class should not be available in iOS 4.0

推荐答案

要检查CLGeocoder是否可用且它是否真的在运行iOS 5,我使用了以下:

To check if CLGeocoder is available and it is really running iOS 5 I used the following:

    if (NSClassFromString(@"CLGeocoder") && 
    [NSClassFromString(@"CLGeocoder") instancesRespondToSelector:
@selector(reverseGeocodeLocation:completionHandler:) ]) {

                        //iOS 5 or later    
       }

这篇关于即使class不可用,NSClassFromString()也会返回一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆