NSClassFromString() returns a class even when class should not be available

前提是你 提交于 2020-01-03 16:57:28

问题


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"))

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

Why? this Class should not be available in iOS 4.0


回答1:


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    
       }


来源:https://stackoverflow.com/questions/9366801/nsclassfromstring-returns-a-class-even-when-class-should-not-be-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!