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

iOS 8 定位失败问题

时间:2015-10-13 21:04:55      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

首先plist定义两个string:
 NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
然后调用
[self.locationManager requestWhenInUseAuthorization]
或者
[self.locationManager requestAlwaysAuthorization]
例如
#import "ViewController.h"
@import CoreLocation;
 
@interface ViewController ()
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
 
@implementation ViewController
 
- (void)viewDidLoad
{
    [super viewDidLoad];
 
    // ** Don‘t forget to add NSLocationWhenInUseUsageDescription in MyApp-Info.plist and give it a string
 
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    }
    [self.locationManager startUpdatingLocation];
}
 
// Location Manager Delegate Methods    
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"%@", [locations lastObject]);
}
 
@end

iOS 8 定位失败问题

标签:

原文地址:http://www.cnblogs.com/isItOk/p/4875545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!