2012-06-16 3 views
1

위치 서비스가 사용 설정되어 있는지 확인하는 앱을 만들기 위해 노력하고 있습니다. 활성화되어 있지 않으면 팝업으로 프롬프트하지만 여전히 위치를 검색하지만 프롬프트가 표시되지 않습니다. 위치 서비스가 활성화 되 자마자 프로세스가 계속 진행됩니다.지속적으로 위치 정보 서비스가 활성화되어 있는지 확인합니다.

어떻게 수행하나요?

+0

유용하다고 판단되면 질문에 답해주십시오. – Raptor

답변

0

당신이 코드를 통해 위치 서비스 가용성을 확인할 수 있습니다

MKUserLocation *userLocation = map.userLocation; 
    BOOL locationAllowed = [CLLocationManager locationServicesEnabled]; 
    BOOL locationAvailable = userLocation.location!=nil; 

    if (locationAllowed==NO) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" 
                 message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } else { 
     if (locationAvailable==NO) 
      [self.map.userLocation addObserver:self forKeyPath:@"location" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil]; 
    } 
+0

고맙습니다. 나는 이것을 시도 할 것이다. – khushalbokadey

+0

그러나이 코드는 위치 서비스가 한번 확인 된 후 확인하지 않습니다. 처음에 위치 서비스가 꺼져 있고 켜져 있으면 사용자가 앱으로 돌아 오면 앱이 그에 따라 작동하지 않습니다. – khushalbokadey

+0

하지만 응용 프로그램에서 서비스를 확인하려고 할 때마다이 메소드를 호출 할 수 있습니다. –

0

.H 파일 INT 카운터에 추가;

[NSTimer scheduledTimerWithTimeInterval:1.0  
          target:self 
          selector:@selector(checkLocationMangerEnabled:)  
          userInfo:nil  
          repeats:YES]; 

counter = 0; 

이제 선택은 다음과 같습니다 :

-(void)checkLocationMangerEnabled:(id)sender 
{ 
    if([CLLocationManager locationServicesEnabled]) 
    { 
     //here location is enabled 
    } 
    else 
    { //Not enabled 
    if(counter == 60) // alert will showed in every 1 min u can increase or decrese 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" 
                message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 
    counter++; 
    } 
} 
1

당신은 위치에 위치하는 경우를 받고 계속할 수는 매초마다 유 증가시킬 수 카운터를 확인합니다로보기의 viewDidLoad에 방법에

이 추가 서비스가 사용 중지되었습니다. 당신이 사용하도록 설정 한 경우

[CLLocationManager locationServicesEnabled] 

를 확인하여 서비스가 활성화되어 있는지 확인 위치를 검색을 계속하려면

,

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation { 
    [locationManager stopUpdatingLocation]; // This will stop to check the location 
} 

[locationManager startUpdatingLocation]; 

그런 위치를 업데이트 시작

이 코드를 제거하고 여전히 [locationManager stopUpdatingLocation]; 위치를 확인하지만 이것은 그는 최선의 접근 방식을 반드시 읽으십시오. apple documentation for the policy of getting the location

관련 문제