我一直在开发一个 iPhone 应用程序,随着最近发布的 iOS 6,我们的客户要求我们制作的应用程序应该支持新的 iOS(该应用程序是作为 iOS 5 应用程序开发的)。
我们的应用在 iOS 5 和 iOS 6 上几乎都能正常运行(除了我现在遇到的几个问题)。但是,我刚刚注意到我在 AppDelegate 中为 CLLocationManager 调用的方法:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
已弃用,在 iOS 6 中我们应该使用以下方法代替:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
当然,我们可以(而且我愿意)使用这种方法。但是我的客户要求我们必须制作支持 iOS 5 和 iOS 6 的应用程序(是的,无论如何我知道这是合理的“需求”)。
要启用 Core Location 同时支持 iOS 5 和 iOS 6,我应该在我的代码中编写哪种方法?有什么办法可以加入一些“如果”之类的条件语句吗?
我很抱歉用这些简单愚蠢的问题打断了社区,但我没有坚实的 Objective-C 和 iPhone 编程背景,而且我还在学习(我确实有一些 Java 经验,但这是我的第一次开发“真正的”应用程序)。
如有任何帮助,我们将不胜感激。 谢谢。
最佳答案
使用
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
并在 target properties-> summery 选项卡中将 Deployment Target
设置为 5.0。它适用于 iOS 5 和 iOS 6
关于ios - OS 5 和 iOS6 中的 CLLocationManager 更新位置(我们应该使用哪个?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13411797/