Xcode 6模拟器的核心位置 [英] Core Location with Xcode 6 simulator

查看:103
本文介绍了Xcode 6模拟器的核心位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

核心位置未调用 didUpdateLocations 。我有2个涉及LocationManager和View Controller的类。为 requestAlwaysAuthorization 设置了Plist。在调试中模拟位置。有人可以帮我发现错误吗?

Core Location is not calling didUpdateLocations. I have 2 classes involved LocationManager and a View Controller. Plist is set for requestAlwaysAuthorization. Location is simulated in debug. Can anyone help me spot the error?

LocationManager.h

LocationManager.h

@interface LPLocationManager : NSObject <CLLocationManagerDelegate>

+(LPLocationManager*)sharedManager;

@property (strong, atomic) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *location;
@end

LocationManager.m

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的地方)

ViewController.m (where startUpdating is called)

- (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];

}


推荐答案

出来。

在模拟器中,转到设置->常规,然后滚动到重置。点击重置位置并隐私。

In simulator, go to Settings -> General and scroll to Reset. Click Reset Location & Privacy.

关闭模拟器并重新运行应用程序。返回设置,转到隐私->位置,然后为该应用选择始终。

Close simulator and rerun app. Back in Settings, go to Privacy -> Location and select Always for the app.

这篇关于Xcode 6模拟器的核心位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆