2014-11-17 3 views
0

iOS 8 시뮬레이터에서 핵심 위치를 사용하려고합니다. 내보기에 'MapKit View' 유형의 객체를 추가했습니다. Atributtes inspector이 선택되어 있습니다.핵심 위치가 사용자로부터 권한을 요청하지 않고 메소드가 호출되지 않음

ViewController.h

#import <UIKit/UIKit.h> 
#import <CoreLocation/CoreLocation.h> 
#import <MapKit/MapKit.h> 

@interface MeuPrimeiroViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>{ 

    IBOutlet MKMapView *mapView; 
} 


@property (nonatomic, strong) CLLocationManager *locationManager; 

@end 

ViewContr : 내 프로젝트에서 내가 ARC을 사용하고 옵션 show user location은 아래에있는 내 코드의 구조 oller.m 내 info.plist 파일에서

@synthesize locationManager; 

    - (void)viewDidLoad { 
     [super viewDidLoad]; 

    if ([CLLocationManager locationServicesEnabled]) { 

      NSLog(@"CLLocationManager locationServicesEnabled == ON"); 

      locationManager = [[CLLocationManager alloc] init]; 
      locationManager.delegate = self; 

      locationManager.distanceFilter = kCLDistanceFilterNone; 
      locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

      // Check for iOS 8 Vs earlier version like iOS7.Otherwise code will 
      // crash on ios 7 
      if ([locationManager respondsToSelector:@selector 
       (requestWhenInUseAuthorization)]) { 
       [locationManager requestAlwaysAuthorization]; 
      } 

      [locationManager startUpdatingLocation]; 




     }else{ 

      NSLog(@"CLLocationManager locationServicesEnabled == OFF"); 
     } 


    } 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ 

    NSLog(@"It works this method is called"); 

} 

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

    NSLog(@"Error: %@",[error description]); 

} 

나는이 값 (String)으로이 키 (NSLocationAlwaysUsageDescription)를 추가합니다. 나는 체크 박스를 해제하면

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first. 

는이 메시지가 사라 : 나는 속성 관리자로 이동하여 체크 박스를 사용하는 경우

내가이 오류 메시지가 나타납니다, 핵심 위치 방법은 호출되지 않습니다 (사용자의 위치를 ​​보여줍니다) 그리고 다시 호출되지 않는 핵심 위치 메서드. londom으로 내비게이션을 변경하고 free run으로 위치를 변경하려고 시도했지만 아무 것도 시도하지 못했습니다. 메소드가 계속 호출되지 않고 코어 위치를 사용하도록 권한 부여 메시지를 표시하지 않았습니다. 나는 이미 모든 것을 시도했다고 믿고, 누구든지이 문제에 대한 제안이나 해결책을 가지고 있습니까?

+0

을하고 있어요 무엇 당신이의 Info.plist 파일에 한 번 더 입력, NSLocationWhenInUseUsageDescription을 필요가 있다고 생각합니다. 또한 iOS 8 인증 상태는 kCLAuthorizationStatusAuthorizedAlways이어야합니다. – Puran

+0

잘 @Puran이 키를 추가하고 이제는 info.plist에 3 개의 키 (NSLocationWhenInUseUsageDescription., kCLAuthorizationStatusAuthorizedAlways, NSLocationAlwaysUsageDescription)가 있습니다. 사용자 위치 표시 및 사용 중지를 설정하려고합니다. 작동하지 않습니다. , 더 이상? –

+0

아래 코드를 추가했습니다. 또한 kCLAuthorizationStatusAuthorizedAlways는 Info.plist에있을 필요가 없습니다. 단지 인증 유형입니다. – Puran

답변

0

이 내가 내 애플 리케이션을위한 일을 완벽하게

- (void)startSignificantChangeUpdates { 
    if (nil == self.locationManager) { 
     self.locationManager = [[CLLocationManager alloc] init]; 
    } 
    self.locationManager.delegate = self; 
    [self.locationManager startMonitoringSignificantLocationChanges]; 
} 

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateLocations:(NSArray *)locations { 
    CLLocation* location = [locations lastObject]; 
    if (location) { 
     self.currentLocation = location; 
     NSString *latitude = [NSString stringWithFormat:@"%f", location.coordinate.latitude]; 
     NSString *longitude = [NSString stringWithFormat:@"%f", location.coordinate.longitude]; 

     self.latLong = [NSString stringWithFormat:@"%@,%@",latitude, longitude]; 
    } 
    if (!self.geocoder) 
     self.geocoder = [[CLGeocoder alloc] init]; 

    [self.geocoder reverseGeocodeLocation:location completionHandler: 
    ^(NSArray* placemarks, NSError* error){ 
     if ([placemarks count] > 0) { 
      CLPlacemark *placemark = [placemarks objectAtIndex:0]; 
      if (placemark.postalCode) { 
       self.currentZipCode = placemark.postalCode; 
      } 
      [[NSNotificationCenter defaultCenter] postNotificationName:@"zipCodeFoundNotification" object:self.currentZipCode userInfo:nil]; 
     } else { 
      [[NSNotificationCenter defaultCenter] postNotificationName:@"zipCodeFoundNotification" object:nil userInfo:nil]; 
     } 
    }]; 
} 

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { 
    if (status != kCLAuthorizationStatusAuthorized && status != kCLAuthorizationStatusNotDetermined) { 
     if (status == kCLAuthorizationStatusDenied){ 
      self.currentZipCode = @"kCLAuthorizationStatusDenied"; 
     } else if (status == kCLAuthorizationStatusRestricted) { 
      self.currentZipCode = @"kCLAuthorizationStatusRestricted"; 
     } 
    } 
} 
관련 문제