核心位置iOS8与iOS7的兼容性

时间:2021-03-15 23:01:13

I have written the following code in my iOS8 compatible app. The app works fine on iOS8, and surprisingly to me, iOS7. My question is, why doesn't this code crash on iOS7?

我在iOS8兼容应用程序中编写了以下代码。该应用程序在iOS8上运行良好,令我惊讶的是iOS7。我的问题是,为什么这个代码在iOS7上没有崩溃?

#import <CoreLocation/CoreLocation.h>
.
.
CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus];
.
// TODO some of these statuses are iOS8 only not iOS7 - need to check.
if ((authStatus == kCLAuthorizationStatusAuthorized) || (authStatus == kCLAuthorizationStatusAuthorizedAlways) ||
(authStatus == kCLAuthorizationStatusAuthorizedWhenInUse))    {
<some actual code>
}

The constants kCLAuthorizationStatusAuthorizedWhenInUse and kCLAuthorizationStatusAuthorizedAlways were introduced with iOS8 so I was expecting tragedy when I tried to run it in the iOS7 simulator but it ran just fine. Is this an issue that I should be worried about on real iOS7 devices (I don't have one any more) or is there something that says this code works on iOS7 that I don't know?

常量kCLAuthorizationStatusAuthorizedWhenInUse和kCLAuthorizationStatusAuthorized总是在iOS8中引入,所以当我试图在iOS7模拟器中运行它时,我期待悲剧,但它运行得很好。这是一个我应该在真正的iOS7设备上担心的问题(我没有更多)或者有什么东西说这个代码适用于我不知道的iOS7吗?

Thank you in advance.

先谢谢你。

1 个解决方案

#1


7  

In iOS7, kCLAuthorizationStatusAuthorizedAlways and kCLAuthorizationStatusAuthorizedWhenInUse enum values are mapped to kCLAuthorizationStatusAuthorized (which is deprecated in iOS 8, by the way) by the iOS8 SDK. That's why you won't be getting any crash.

在iOS7中,kCLAuthorizationStatusAuthorizedAlways和kCLAuthorizationStatusAuthorizedWhenInUse枚举值被映射到iOS8 SDK中的kCLAuthorizationStatusAuthorized(在iOS 8中不推荐使用)。这就是为什么你不会遇到任何崩溃。

#1


7  

In iOS7, kCLAuthorizationStatusAuthorizedAlways and kCLAuthorizationStatusAuthorizedWhenInUse enum values are mapped to kCLAuthorizationStatusAuthorized (which is deprecated in iOS 8, by the way) by the iOS8 SDK. That's why you won't be getting any crash.

在iOS7中,kCLAuthorizationStatusAuthorizedAlways和kCLAuthorizationStatusAuthorizedWhenInUse枚举值被映射到iOS8 SDK中的kCLAuthorizationStatusAuthorized(在iOS 8中不推荐使用)。这就是为什么你不会遇到任何崩溃。