2012-10-24 63 views
0

我在尋找當前位置時遇到了困難,在使用CLLocationManager時它會要求一個通知,比如「您想使用當前位置」嗎?在那裏有兩個選項命名爲:1.OK 2.Dont允許。是否有可能爲此編寫兩個按鈕自定義動作......如果做到這一點,與此相關的,那麼將是對我來說非常有用有任何想法,任何人..CLLocationManager的按鈕動作(當前位置彈出)

感謝的提前...

回答

0

讓法這樣並將其連接到您的按鈕或從viewDidLoad中調用它

-(void) showLocation 
{ 
    // put an alerview to ask user for allow/disallow 
} 

//在alerView委託方法,agains是按鈕使用戶當前的位置

0

我不認爲你可以重寫的行爲對於此警報。但是,您可以實現CLLocationManager的委託方法

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error; 

在那裏你可以發現用戶是否已經爲您的應用程序啓用與否位置服務。

以下是適用於上述方法

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 

    [self.locationManager stopUpdatingLocation]; 
    switch([error code]) { 
     case kCLErrorDenied: 
      //User has not enabled location services for this app. 
      break; 
     case kCLErrorLocationUnknown: 
      //location could not be found 
      break; 
     default: 
      //some other issue 
      break; 
    } 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"An error title" 
                message:@"An error message" 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    [alert show]; 

} 
一個實現的示例
相關問題