ios – 没有调用CLLocation didupdatetolocation

ios – 没有调用CLLocation didupdatetolocation,第1张

概述花了几天时间试图解决这个问题但无法找到任何有效的解决方案.我已经检查了stackoverflow上的所有帖子,并尝试了所有他们的解决方案,似乎没有任何工作.我也尝试过CLLocation的苹果测试项目,对我来说很好.我使用了苹果测试项目的点点滴滴 https://developer.apple.com/library/ios/samplecode/LocateMe/Listings/README_ 花了几天时间试图解决这个问题但无法找到任何有效的解决方案.我已经检查了stackoverflow上的所有帖子,并尝试了所有他们的解决方案,似乎没有任何工作.我也尝试过CLLocation的苹果测试项目,对我来说很好.我使用了苹果测试项目的点点滴滴

https://developer.apple.com/library/ios/samplecode/LocateMe/Listings/README_md.html

但我的代码根本不起作用. DIDupdatetoLocation永远不会被调用.

这是我的代码(在vIEwDIDLoad中)

_locationManager = [[CLLocationManager alloc] init];self.locationManager.delegate = self;// This is the most important property to set for the manager. It ultimately determines how the manager will// attempt to acquire location and thus,the amount of power that will be consumed.self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;// Once configured,the location manager must be "started"//// for iOS 8,specific user level permission is required,// "when-in-use" authorization grants access to the user's location//// important: be sure to include NSLocationWhenInUseUsageDescription along with its// explanation string in your Info.pList or startUpdatingLocation will not work.//if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {    [self.locationManager requestWhenInUseAuthorization];}[self.locationManager startUpdatingLocation];[self performSelector:@selector(stopUpdatingLocationWithMessage:)           withObject:@"Timed Out"           afterDelay:30];

我已检查以确保启用locationServicesEnabled.

我已将NSLoationWhenInUseUsageDescription属性添加到info.pList文件中.我需要添加或启用任何服务吗?

我不能因为上帝的爱而弄清楚我做错了什么.有人可以帮我这个.

解决方法 在iOS8上收到dIDChangeAuthorizationStatus回调后,你必须调用startUpdatingLocation.
//iOS 8 API changeif([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){    [self.locationManager requestWhenInUseAuthorization];}else{    [self.locationManager startUpdatingLocation];}

实现这个委托方法:

-(voID)locationManager:(CLLocationManager *)manager dIDChangeAuthorizationStatus:(CLAuthorizationStatus)status{    switch (status) {        case kCLAuthorizationStatusNotDetermined:        case kCLAuthorizationStatusRestricted:        case kCLAuthorizationStatusDenIEd:        {            // do some error handling        }            break;        default:{            [self.locationManager startUpdatingLocation];        }            break;    }}
总结

以上是内存溢出为你收集整理的ios – 没有调用CLLocation didupdatetolocation全部内容,希望文章能够帮你解决ios – 没有调用CLLocation didupdatetolocation所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1097878.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存