我为ios创建了一个通用框架。在框架中,我有一个提供gps位置的类。该类使用 import CoreLocation / CoreLocation.h 。但是CoreLocation框架不应该属于我自己的框架。所以我必须检查框架是否存在。为了提供这个,我使用NSClassFromString,就像在示例中一样。
但是,如果我从未将CoreLocation添加到我自己的框架或使用我的框架的应用程序,这个例子也有效。它为什么有效?这可能是在苹果评论中拒绝该应用程序的原因吗?
#import <CoreLocation/CoreLocation.h>
...
-(void)init {
self = [super init];
Class CLLocationManagerOrNil = NSClassFromString(@"CLLocationManager");
if (CLLocationManagerOrNil) {
_locationManager = [[CLLocationManagerOrNil alloc] init];
_locationManager.delegate = self;
// update location
[_locationManager startUpdatingLocation];
}
return self;
}
答案 0 :(得分:0)
#import <CoreLocation/CoreLocation.h>
框架,也允许 CoreLocation
。更重要的是,您可以根据需要添加所有系统框架。
但他们没有工作!你会收到类似
的错误Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_CLLocationManager", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
在您的代码中,它永远不会进入if (CLLocationManagerOrNil)
块,这就是您认为它正在运行的原因。