Get Which iOS Frameworks are Available?
I'm writing a static library for iOS. I want to prog开发者_运维百科rammatically figure out if CoreLocation is added to the project, is there any way to do that?
Probably something like:
if(NSClassFromString(@"CLLocationManager"))
{
NSLog(@"CoreLocation is available");
}
Would do it. NSClassFromString takes an NSString and checks whether there's a class of that name currently available in the runtime. If so then it returns the Class
object, otherwise it returns nil. The if statement there effectively compares to nil.
So, the logic you're applying is "does a class called CLLocationManager currently exist?", which is a proxy for checking that CoreLocation is loaded because it's one of the fundamental classes to that framework.
精彩评论