2012-11-20 24 views
1

對於Objective-C來說,我相當新,我試圖找到用戶的位置。下面是我的,但有一個解析問題(![cLLocationManager locationServicesEnabled])CLLocationManager locationServicesEnabled ios6

我認爲它已被棄用的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;   
    } 
} 

任何幫助將不勝感激。

+0

我看到您更新了您的問題中的原始代碼並進行了必要的修復。這是不好的形式。現在如果有人看到你的問題和答案,那沒有任何意義。一旦提供答案,切勿修改原始問題。您可以添加到問題中,但不要修改原始文本。 – rmaddy

回答

1

+ (BOOL)locationServicesEnabled還沒有被棄用,因此類的方法應該能正常運行。

您是否已將相關導入添加到您的班級中?

#import <CoreLocation/CoreLocation.h> 
+0

我在我的.h中有#import ,我也把它放在.m中,但仍然沒有工作 –

+0

OK。 Xcode顯示的錯誤/警告究竟是什麼? –

+0

我想通了,我有一stopUpdatingLocation,並遺漏了使用locationServicesEnabled startUpdatingLocation所以這是一直以來的問題謝謝 –

1

你有一個額外的'['問題和方法是錯誤的。您有:

if (![[CLLocationManager locationServiceEnabled]) 

它應該是:

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

我改變了簡單的語法錯誤,但沒有運氣,即時通訊沒有得到intellisense locationServicesEnabled –

+0

@ThomasMannion你的問題是關於語法問題,就是這樣。我給你答案。 14小時後,發佈了另一個答案,該答案不回答您的原始問題,並將該答案標記爲接受的答案。奇怪。 – rmaddy

相關問題