2016-09-09 3 views
0

모든 위치의 위치 속성을 가져올 수있는 앱을 개발하려고합니다. 이위치 관리자 대리인이 iOS objective-c에서 호출되지 않았습니다.

  @interface ViewController : UIViewController <CLLocationManagerDelegate, CBCentralManagerDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate> 
      { 
       CLLocationManager *locationManager; 
       CMMotionManager  *motionManager; 
      } 
      @property(nonatomic, strong) CLLocationManager *locationManager; 
      @end 

이 ViewController.m이

locationManager = [[CLLocationManager alloc] init]; 

- (void)startAllDataRec 
{ 
    [self getLocation]; 
} 

- (void)getLocation 
{ 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

    if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) 
    { 
    [locationManager requestAlwaysAuthorization]; 
    } 

    //Checking authorization status 
    if (![CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) 
    { 
    NSLog(@"you are denied a permission"); 
    } 
    else 
    { 
    //Location Services Enabled, let's start location updates 
    [locationManager startUpdatingLocation]; 
    } 

} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    NSLog(@"didFailWithError: %@", error); 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    NSLog(@"didUpdateToLocation: %@", newLocation); 
    CLLocation *currentLocation = newLocation; 

    if (currentLocation != nil) { 
     mLat = currentLocation.coordinate.latitude; 
     mLon = currentLocation.coordinate.longitude; 
     mSpeed = currentLocation.speed; 
     mAlt = currentLocation.altitude; 
     mCourse = currentLocation.course; 
     NSLog(@"lat lon speed alt course = %f, %f, %f, %f, %f", mLat, mLon, mSpeed, mAlt, mCourse); 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      self.speedLbl.text = [NSString stringWithFormat:@"%f", mSpeed]; 
     }); 

    } 
    else{NSLog(@"current location is nil");}; 
} 

이 문제가 대리자에서 호출되지 않고있다 장치의 위치

ViewController.h를 얻기 위해 지금 내가 가지고있는 코드입니다 언제든지 액세스 권한을 부여 할 때조차도 트리거되지 않음 누락 된 항목이 있습니까? 먼저 호출해야합니까?

+0

add locationManager = [[CLLocationManager alloc] init]; getLocation 메소드에서 getLocation을 호출하고 viewwillappear에서 getLocation을 호출하십시오. 위치를 확인하기 전에 사용자 권한을 요청해야합니다. 나는이 누구도 보지 못했다. Google CLLocationManager 자습서. 그들 중 많은 사람들이 밖에 있습니다. –

+0

CLLocations에 대한 많은 자습서를 확인했는데 사용자 권한 문제가 표시되지 않았습니다. 하지만 무슨 뜻인지 알 겠어. 내가 뭘 할 수 있는지 보려고 노력할거야. – Nik391

+0

나는 내 질문을 업데이트하고 인증 액세스를 부여했지만 여전히 문제는 동일합니다 – Nik391

답변

0

당신이 언급하지 않았기 때문에 가장 가능성있는 이유는 앱의 Info.plist 파일에 NSLocationAlwaysUsageDescription이 없다는 것입니다. "항상"위치 업데이트를 원한다면 (iOS 8 이후)이 필요합니다.

다른 몇 가지 : 사용자가 위치 정보에 대한 권한을 준 경우 CLLocationManager 당신을 말할 것이다 곳이기 때문에 당신은 대리인에 locationManager:didChangeAuthorizationStatus:를 구현해야

  • .
  • iOS 7 이전 버전을 지원하지 않는 한 귀하의 respondsToSelector 수표는 불필요합니다.
+0

멋진예요! 감사 – Nik391

관련 문제