Mat*_*man 4 location objective-c cllocationmanager ios ios-simulator
获取我当前位置的问题.我仍然得到错误:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
Run Code Online (Sandbox Code Playgroud)
我已经完成了我在这里找到的所有内容:
重置iOS模拟器中的内容和设置(模拟器中的地图应用程序显示正确的位置).
在Xcode中的产品>方案>编辑我没有标记允许位置模拟(当我标记它时,它模拟例如伦敦).
我已将NSLocationWhenInUseUsageDescription添加到我项目中的Info.plist文件中(App要求获取位置权限,我可以在iOS模拟器的"设置"中看到它们).
我打开了Wi-Fi连接(就像我说的定位服务在Safari,地图甚至iOS模拟器中的地图中工作正常).
-(void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if(IS_OS_8_OR_LATER){
NSUInteger code = [CLLocationManager authorizationStatus];
if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) {
if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
[self.locationManager requestWhenInUseAuthorization];
} else {
NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription");
}
}
}
[self.locationManager startUpdatingLocation];
[self.FirstMap setShowsUserLocation:YES]; }
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show]; }
Run Code Online (Sandbox Code Playgroud)
有什么我忘了吗?谢谢!
我想也许你需要首先阅读这个帖子,因为它在很大程度上是重叠的.
但无论如何,我测试了你的代码并得到了与你报告的相同的错误.然后我改变了模拟配置.具体来说,在模拟器中,我单击调试 - >位置 - >自定义位置...并输入一个坐标,我可以定期接收位置事件(以每秒每个样本的速度.)所以可能问题不是来自代码,但来自模拟器本身.希望我的回答有所帮助
UPDATE
我想我误解了你的问题.你想要的是"自动"在模拟器中获取你当前的位置.我担心xcode中没有这样的功能,相反,你需要使用"添加gpx文件到项目",这比使用自定义位置更加重要.但我的意思是,如果你已经成功找到了正确的位置,为什么它让你无法从模拟器中获得正确的当前位置,或者替代方案,也许你可以在手机上进行测试?
| 归档时间: |
|
| 查看次数: |
14187 次 |
| 最近记录: |