核心位置未調用didUpdateLocations
。我有兩個類涉及LocationManager和一個視圖控制器。 Plist設置爲requestAlwaysAuthorization
。位置在調試中模擬。任何人都可以幫助我發現錯誤?使用Xcode 6模擬器的核心位置
LocationManager.h
@interface LPLocationManager : NSObject <CLLocationManagerDelegate>
+(LPLocationManager*)sharedManager;
@property (strong, atomic) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *location;
@end
LocationManager.m
+(LPLocationManager*)sharedManager{
static LPLocationManager *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[LPLocationManager alloc]init];
});
return sharedManager;
}
- (id)init
{
self = [super init];
if (self) {
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = 10;
}
return self;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
self.location = [locations lastObject];
[self setCurrentLocation:self.location];
NSLog(@"self.location in didupdatelocation %@", self.location);
[self.locationManager stopUpdatingLocation];
}
ViewController.m(其中startUpdating叫)
- (void)refresh:(UIRefreshControl *)refreshControl {
LPLocationManager *locationObject = [LPLocationManager sharedManager];
NSLog(@"location object %@", locationObject);
[locationObject.locationManager requestAlwaysAuthorization];
NSLog(@"locationManager %@", locationObject.locationManager);
[locationObject.locationManager startUpdatingLocation];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(getLocation:) name:@"locationNotification" object:nil];
[refreshControl endRefreshing];
}
http://stackoverflow.com/questions/25844430/xcode-6-gm-cllocationmanager/25844674#25844674 – 2014-09-25 05:50:10