Jan*_*Jan 1 objective-c cllocationmanager ios ios8
我们正在制作一个与iOS 8兼容的应用程序,但与此同时,我们的一些开发人员还没有Xcode 6,因此他们在尝试调用时遇到此错误
[self.locationManager requestAlwaysAuthorization];
Run Code Online (Sandbox Code Playgroud)
即使它在if里面
if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
[self.locationManager requestAlwaysAuthorization];
}
Run Code Online (Sandbox Code Playgroud)
我们怎么解决这个问题才能在Xcode 5上编译?
以下是处理此问题的正确方法.这假定您的应用程序具有iOS 7.x或更早版本的"部署目标",您需要使用"Base 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2687 次 |
| 最近记录: |