Objective c 当前位置代码在iOS 5中不起作用,但在iOS 6中可以正常工作
我下载了一个当前位置示例项目,该项目在iOS 5和iOS 6中运行良好。当我将相同的文件复制到另一个项目时,它在iOS 5下停止工作,但在iOS 6下工作正常。我犯了一个错误Objective c 当前位置代码在iOS 5中不起作用,但在iOS 6中可以正常工作,objective-c,ios5,xcode4.5,Objective C,Ios5,Xcode4.5,我下载了一个当前位置示例项目,该项目在iOS 5和iOS 6中运行良好。当我将相同的文件复制到另一个项目时,它在iOS 5下停止工作,但在iOS 6下工作正常。我犯了一个错误 didFailWithError: Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.) 我的代码是: .h #import <UIKit/UIKit.h> #imp
didFailWithError: Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.)
我的代码是:
.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
CLGeocoder *geocoder;
CLPlacemark *placemark;
}
@property (weak, nonatomic) IBOutlet UILabel *lblLat;
@property (weak, nonatomic) IBOutlet UILabel *lblLong;
@property (weak, nonatomic) IBOutlet UILabel *lblAddress;
@end
谁能告诉我问题出在哪里吗?我使用的是Xcode 4.5,iOS部署目标是iOS 5
谢谢。我不知道为什么它在iOS6中工作,因为下面的委托方法已经被弃用了
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
您可以尝试将其替换为:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
根据文档kclerordomain code=1
也表示:
kCLErrorLocationUnknown
您是否通过XCode模拟您的位置?弃用并不意味着该方法在iOS 6中无法运行,而是意味着它应该在即将发布的iOS 7甚至8版本中删除,无论如何,如果您计划支持iOS 5设备,您必须使用不推荐的方法,因为第二种方法可以从iOS 6和以后使用。您是否检查了应用程序是否具有获取位置更新的权限?我的意思是从手机设置的隐私部分
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations