2009-12-15 51 views
7

應用程序第一次嘗試獲取用戶位置時,系統會提示他們「想使用您的當前位置」,並且可能會觸及不允許或不正常。有什麼方法可以確定用戶是否打好或不允許?我試圖讓MKMapView顯示用戶當前位置,但我想根據用戶選擇採取不同的操作。檢查用戶是否允許應用程序使用他們的位置

通常情況下,您會認爲會有代表獲取此信息,但似乎沒有。

在此先感謝您的幫助。

回答

16

您的第一次獲取用戶位置的電話將失敗,並顯示一條錯誤消息,告訴您用戶拒絕了位置服務。您的CLLocationManagerDelegate方法didFailWithError將被調用,如下所示。 (常數在CLError.h中定義)

- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError 
{ 
    switch([anError code]) 
    { 
    case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying 
    break; 

    case kCLErrorDenied: // CL access has been denied (eg, user declined location use) 
    message = @"Sorry, flook has to know your location in order to work. You'll be able to see some cards but not find them nearby"; 
    break; 

    case kCLErrorNetwork: // general, network-related error 
    message = @"Flook can't find you - please check your network connection or that you are not in airplane mode"; 
    } 
} 
+1

就是我在找的東西! – Codezy

+0

這似乎並不是這種情況startMonitoringSignificantLocationChanges –

相關問題