didUpdateLocations:在运行iOS 7的设备上未调用的方法

时间:2013-12-17 09:05:02

标签: ios core-location cllocationmanager

我面临一个奇怪的问题。我在用 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations获取设备位置。它在simulator (iOS 6 and iOS 7)iPhone 4S running iOS 6.1.3上正常运行。当我将iPhone 4 running iOS 7连接到系统并安装应用程序时,它也正常工作,但是一旦我拔下设备并重新运行应用程序,此方法就不会被调用,我也找不到该位置。我怎样才能克服这个问题?

1 个答案:

答案 0 :(得分:-1)

您是如何设置位置管理器的?

你的界面是否有:

@interface ViewController : UIViewController <CLLocationManagerDelegate> {
    @property (strong, nonatomic) CLLocationManager *locationManager;
}

然后在viewDidLoad中实现:

// setup location manager
    if ([CLLocationManager locationServicesEnabled]) {
        _locationManager = [[CLLocationManager alloc] init];

        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.delegate = self;

        [_locationManager startUpdatingLocation];
    }

您需要实现委托:

locationManager:didUpdateLocations:

小心:在IOS 7中

locationManager:didUpdateToLocation:fromLocation

已弃用。 Apple link to CLLocationManagerDelegate