为什么iOS8中的CLLocationManager startUpdatingLocation没有?

为什么iOS8中的CLLocationManager startUpdatingLocation没有?,第1张

概述我使用XCode 6附带的模拟器测试iOS 8.0中的现有位置功能.我无法获得 CLLocationManager.startUpdatingLocation触发 CLLocationManagerDelegate.locationManager:didUpdateLocations或 CLLocationManagerDelegate.locationManager:didFailWithErr 我使用XCode 6附带的模拟器测试iOS 8.0中的现有位置功能.我无法获得 CLLocationManager.startUpdatingLocation触发 CLLocationManagerDelegate.locationManager:didUpdateLocations或
CLLocationManagerDelegate.locationManager:didFailWithError.

我没有得到“”我的应用程序“想要使用您的当前位置”警报,就像我在iOS 7.0.3模拟器上做的那样.我已使用Google地图应用验证模拟的位置设置.

这在iOS 7.0.3模拟器中工作正常.

我哪里错了?

解决方法 iOS 8要求在调用CLLocationManager.startUpdatingLocation之前调用 CLLocationManager.requestWhenInUseAuthorization或 CLLocationManager.requestAlwaysAuthorization.

@interface MyVIEwController : UIVIEwController <CLLocationManagerDelegate>@property CLLocationManager *locationManager;@end

requestWhenInUseAuthorization和requestAlwaysAuthorization异步运行,因此您希望确保在使用之前不清除您的CLLocationManager对象,以响应警报.

- (voID) vIEwDIDAppear:(BOol)animated {    if ([CLLocationManager locationServicesEnabled]) {        self.locationManager = [CLLocationManager new];        self.locationManager.delegate = self;        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;        SEL selector = NSSelectorFromString(@"requestWhenInUseAuthorization");        if ([self.locationManager respondsToSelector:selector]) {            [self.locationManager requestWhenInUseAuthorization];        } else {            [self.locationManager startUpdatingLocation];        }    } else {        ...    }}- (voID)locationManager:(CLLocationManager *)manager dIDChangeAuthorizationStatus:(CLAuthorizationStatus)status {    if (status == kCLAuthorizationStatusAuthorizeDWhenInUse) {        [self.locationManager startUpdatingLocation];    } else if (status == kCLAuthorizationStatusAuthorized) {        // iOS 7 will redundantly call this line.        [self.locationManager startUpdatingLocation];    } else if (status > kCLAuthorizationStatusNotDetermined) {        ...    }}- (voID)locationManager:(CLLocationManager *)manager dIDUpdateLocations:(NSArray *)locations {    ...}- (voID)locationManager:(CLLocationManager *)manager dIDFailWithError:(NSError *)error {    ...}

实现CLLocationManagerDelegate时,您现在也需要实现locationManager:didChangeAuthorizationStatus:方法.在此方法中,您可以检查用户是否已授予应用程序权限,并采取相应措施.

如果[CLLocationManager authorizationStatus] = nil,则当authorizationStatus设置为kCLAuthorizationStatusNotDetermined时,将调用locationManager:dIDChangeAuthorizationStatus:当用户从警告对话框中进行选择时,将再次调用.

总结

以上是内存溢出为你收集整理的为什么iOS8中的CLLocationManager startUpdatingLocation没有?全部内容,希望文章能够帮你解决为什么iOS8中的CLLocationManager startUpdatingLocation没有?所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1006190.html

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

发表评论

登录后才能评论

评论列表(0条)

保存