'CLLocationManager'没有可见的@interface声明选择器'requestAlwaysAuthorization' [英] No visible @interface for 'CLLocationManager' declares the selector 'requestAlwaysAuthorization'
问题描述
我们正在制作一款与iOS 8兼容的应用程序,但与此同时,我们的一些开发人员还没有Xcode 6,因此他们在尝试调用时遇到此错误
We are making an app to be compatible with iOS 8, but at the same time, some of our developers do not have Xcode 6 yet, so they are getting this error when trying to call
[self.locationManager requestAlwaysAuthorization];
即使它位于if
if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
[self.locationManager requestAlwaysAuthorization];
}
我们如何解决这个问题才能在Xcode 5上编译?
How can we solve this to compile on Xcode 5?
推荐答案
以下是处理此问题的正确方法。这假设您的应用程序具有iOS 7.x或更早版本的部署目标,您需要使用Base SDK的不同值编译项目(例如Xcode 6下的iOS 8和Xcode 5下的iOS 7):
The following is the proper way to deal with this. This assumes that your app has a "Deployment Target" of iOS 7.x or earlier and you need to compile the project with different values for the "Base SDK" (such as iOS 8 under Xcode 6 and iOS 7 under Xcode 5):
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// Being compiled with a Base SDK of iOS 8 or later
// Now do a runtime check to be sure the method is supported
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
} else {
// No such method on this device - do something else as needed
}
#else
// Being compiled with a Base SDK of iOS 7.x or earlier
// No such method - do something else as needed
#endif
这篇关于'CLLocationManager'没有可见的@interface声明选择器'requestAlwaysAuthorization'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!