【问题标题】:what is deprecated? how to handled it in all the version?什么被弃用了?如何在所有版本中处理它?
【发布时间】:2014-10-30 06:13:00
【问题描述】:

我正在使用核心位置我的开发目标是 5.0 下面是我开始更新的代码

    self.locationManager = [[CLLocationManager alloc]init];
    [self.locationManager setDelegate:self];
    [self.locationManager startUpdatingLocation];

下面是委托方法

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
     // Do Something Here
}

它在 iOS 5.0 和 6.0 中调用,但在 iOS 7.0 之后被弃用 所以对于 iOS 7.0 及以上我必须在下面使用

- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations
{
    // Do Something Here
}

我的问题是我是否必须为 7.0 以下和 7.0 以上的 iOS 管理两个单独的委托方法?

如果不是请详细解释我。

【问题讨论】:

    标签: ios objective-c xcode gps core-location


    【解决方案1】:

    请在此处阅读此文档 -

    要使其与 iOS 5 兼容,请在此函数中调用较新版本的方法

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    

    http://www.devfright.com/how-to-make-didupdatelocations-compatible-with-ios-5-and-ios-6/

    【讨论】:

    【解决方案2】:

    将您的开发目标设为 iOS 5.0。如果是这种情况,这些警告将不会出现。您可以使用已弃用的委托,因为正在使用的编译器不知道弃用。现在可能存在您需要在未来的项目中包含此源代码的情况。这些项目可能仅支持 iOS7 及更高版本。如果是这种情况,与两位代表一起工作以避免问题总是安全的。

    您也可以像这样使用#pragma 关闭警告:

    // pre-iOS6.0
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [self dismissModalViewControllerAnimated:YES];
    #pragma clang diagnostic pop
    

    欲了解更多信息,请查看此帖子:deprecated warnings in xcode and how to handle deprecation

    【讨论】:

      猜你喜欢
      • 2022-11-20
      • 1970-01-01
      • 2021-04-14
      • 2011-01-13
      • 1970-01-01
      • 2021-11-05
      • 2012-05-07
      • 1970-01-01
      • 2015-02-28
      相关资源
      最近更新 更多