CLLocationManager locationServicesEnabled ios6

时间:2012-11-20 23:45:02

标签: objective-c core-location ios6

我是Objective-C的新手,我试图找到用户的位置。以下是我的内容,但(![cLLocationManager locationServicesEnabled])存在解析问题。

我认为iOS6已被弃用,但我无法找到要使用的内容。

- (void)updateLabels {
    if (location != nil) {
        self.latitudeLabel.text = [NSString stringWithFormat:@"%.8f",location.coordinate.latitude];
        self.longitudeLabel.text = [NSString stringWithFormat:@"%.8f",location.coordinate.longitude];
    } else {
        self.longitudeLabel.text = @"";
        self.latitudeLabel.text = @"";

        NSString *statusMessage;
        if ([lastLocationError.domain isEqualToString:kCLErrorDomain] && lastLocationError.code == kCLErrorDenied) {
            statusMessage = @"Location Services Disabled";
        } else {
            statusMessage = @"Error Getting Location";
        } else if (![CLLocationManager locationServicesEnabled]) { //Problem lies here
            statusMessage = @"Location Services Disabled";
        } else if (updatingLocation) {
            statusMessage = @"Searching...";
        } else {
            statusMessage = @"Press the Button to start";
        }

        self.messageLabel.text = statusMessage;         
    }
}

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

你有一个额外的'['与问题一致,方法是错误的。你有:

if (![[CLLocationManager locationServiceEnabled])

应该是:

// Remove extra [ and spell method name correctly
if (![CLLocationManager locationServicesEnabled])

答案 1 :(得分:1)

类方法+ (BOOL)locationServicesEnabled尚未弃用,因此应该可以正常工作。

您是否已将相关导入添加到班级?

#import <CoreLocation/CoreLocation.h>