1

我对 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;         
    }
}

任何帮助都感激不尽。

4

2 回答 2

1

你有一个额外的'['在问题所在的行并且方法是错误的。你有:

if (![[CLLocationManager locationServiceEnabled])

它应该是:

// Remove extra [ and spell method name correctly
if (![CLLocationManager locationServicesEnabled])
于 2012-11-21T00:32:41.140 回答
1

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

您是否已将相关导入添加到您的课程中?

#import <CoreLocation/CoreLocation.h>
于 2012-11-21T14:35:06.823 回答