首页 > 移动平台 > 详细

ios8定位问题(建议CLLocationManager 和MKMapView 结合使用)

时间:2015-02-02 14:17:12      阅读:278      评论:0      收藏:0      [点我收藏+]

1.在info.plist中添加key NSLocationWhenInUseUsageDescription、NSLocationAlwaysUsageDescription。

2.CLLocationManager 切记定义成成员变量、或者属性,否则导致不弹出系统提示打开定位提示框

3.直接上代码

#pragma mark - CLLocationManagerDelegate

- (void)startLocation{

    self.locationmanager = [[CLLocationManager alloc] init];

    self.locationmanager.delegate = self;

}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{

    switch (status) {

        case kCLAuthorizationStatusNotDetermined:

            if([self.locationmanager respondsToSelector:@selector(requestAlwaysAuthorization)]){

                [self.locationmanager requestWhenInUseAuthorization];

            }

            break;

        case kCLAuthorizationStatusDenied:

            [UIAlertView bk_alertViewWithTitle:@"请在设置-隐私-定位服务中开启定位功能!"];

            break;

        case kCLAuthorizationStatusRestricted:

            [UIAlertView bk_alertViewWithTitle:@"定位服务无法使用!"];

        default:

            break;

    }

}

4.开启定位后直接使用MKMapView定位。

ios8定位问题(建议CLLocationManager 和MKMapView 结合使用)

原文:http://my.oschina.net/751547752/blog/374392

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!