简体   繁体   English

'CLLocationManager'的可见@interface没有声明选择器'requestAlwaysAuthorization'

[英]No visible @interface for 'CLLocationManager' declares the selector 'requestAlwaysAuthorization'

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 我们正在开发一个与iOS 8兼容的应用程序,但与此同时,我们的一些开发人员还没有Xcode 6,因此他们在尝试调用时遇到此错误

[self.locationManager requestAlwaysAuthorization];

Even if it is inside an if 即使在if里面

if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
    [self.locationManager requestAlwaysAuthorization];
}

How can we solve this to compile on Xcode 5? 我们如何解决这个问题以在Xcode 5上进行编译?

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): 假设您的应用具有iOS 7.x或更早版本的“部署目标”,并且您需要使用“基础SDK”的不同值来编译项目(例如Xcode 6下的iOS 8和Xcode 5下的iOS 7):

#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

Accepted answer didn't work for my particular situation. 接受的答案不适用于我的特殊情况。 Due to build enviroment limitations (Phonegap/Cordova) I'm stuck on compiling against the iOS7 SDK only. 由于构建环境的限制(Phonegap / Cordova),我只能使用iOS7 SDK进行编译。

I implemented the following (as suggested in comments): 我实现了以下内容(如评论中所建议):

 if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
    // Use performSelector: so compiler won't blow up on this
    [self.locationManager performSelector:@selector(requestAlwaysAuthorization)];
}    

It might show compiler warnings, but atleast it works in that specific case. 它可能显示编译器警告,但至少在特定情况下有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM