No visible @interface for 'CLLocationManager' declares the selector 'requestAlwaysAuthorization'

依然范特西╮ 提交于 2020-01-15 11:14:30

问题


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];

Even if it is inside an if

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

How can we solve this to compile on Xcode 5?


回答1:


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



回答2:


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.

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.



来源:https://stackoverflow.com/questions/25626797/no-visible-interface-for-cllocationmanager-declares-the-selector-requestalwa

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