码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-02-02 14:19:10      阅读:178      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!