2014-10-06 14 views
6

Spędziłem kilka dni próbując rozwiązać ten problem, ale nie mogłem znaleźć żadnych rozwiązań, które działają. Sprawdziłem wszystkie posty na stackoverflow i wypróbowałem wszystkie ich rozwiązania i wydaje się, że nic nie działa. Wypróbowałem także test jabłkowy na CLLocation, który działa dobrze dla mnie. Użyłem kawałki z projektu badawczego jabłkoCLLocation didupdatetolocation nie nazywane

https://developer.apple.com/library/ios/samplecode/LocateMe/Listings/README_md.html

Ale mój kod nie działa w ogóle. DidupdateToLocation nigdy nie zostanie wywołany.

Oto mój kod (w viewDidLoad)

_locationManager = [[CLLocationManager alloc] init]; 

self.locationManager.delegate = self; 



// This is the most important property to set for the manager. It ultimately determines how the manager will 

// attempt to acquire location and thus, the amount of power that will be consumed. 

self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 



// Once configured, the location manager must be "started" 

// 

// for iOS 8, specific user level permission is required, 

// "when-in-use" authorization grants access to the user's location 

// 

// important: be sure to include NSLocationWhenInUseUsageDescription along with its 

// explanation string in your Info.plist or startUpdatingLocation will not work. 

// 

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 

    [self.locationManager requestWhenInUseAuthorization]; 

} 

[self.locationManager startUpdatingLocation]; 



[self performSelector:@selector(stopUpdatingLocationWithMessage:) 

      withObject:@"Timed Out" 

      afterDelay:30]; 

I zostały sprawdzone, aby upewnić locationServicesEnabled jest włączony.

Dodałem właściwość NSLoationWhenInUseUsageDescription do pliku info.plist. Czy istnieje jakakolwiek inna właściwość, którą muszę dodać lub udostępnić dowolne usługi?

Nie mogę z miłości do Boga dowiedzieć się, co zrobiłem źle. Czy ktoś mógłby mi z tym pomóc.

+0

btw pojawia się alert autoryzacji? –

+0

Alert autoryzacji nie pojawia się – dogwasstar

+1

Wtedy domyślam się, że callback didChangeAuthorizationStatus nie został wywołany, prawda? Usługa lokalizacyjna dla aplikacji jest włączona? (Ustawienia/Prywatność/Usługi lokalizacyjne) Czy jesteś pewien, że dodałeś właściwy klucz do swojej .plist? –

Odpowiedz

0

Głupi mnie. Dodałem słowa kluczowe do niewłaściwego pliku plist. Mam to teraz działa. Dzięki za pomoc dla facetów.

6

Po wywołaniu wywołania didChangeAuthorizationStatus w systemie iOS8 należy wywołać funkcję startUpdatingLocation.

//iOS 8 API change 
if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){ 
    [self.locationManager requestWhenInUseAuthorization]; 
}else{ 
    [self.locationManager startUpdatingLocation]; 
} 

wdrożenia tej metody Delegat:

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 
{ 
    switch (status) { 
     case kCLAuthorizationStatusNotDetermined: 
     case kCLAuthorizationStatusRestricted: 
     case kCLAuthorizationStatusDenied: 
     { 
      // do some error handling 
     } 
      break; 
     default:{ 
      [self.locationManager startUpdatingLocation]; 
     } 
      break; 
    } 
} 
6

Po pierwsze, nie zapomnieć o IOS 8 trzeba zrobić [locationManager requestWhenInUseAuthorization] Plus [locationManager requestAlwaysAuthorization];

_locationManager = [CLLocationManager new]; 

if(SYSTEM_IS_OS_8_OR_LATER) { 
    [_locationManager requestWhenInUseAuthorization]; 
    [_locationManager requestAlwaysAuthorization]; 

} 

_locationManager.delegate = self; 
_locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
//and the problem with your code : don't forget to start 
_locationManager startUpdatingLocation]; 

iw swoim didUpdateLocations

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ 

     _currentLocation = [locations objectAtIndex:0]; 
     //do your stuff with the location 

    } 
+0

cudownie. Dodanie zarówno 'requestWhenInUseAuthorization' i' requestAlwaysAuthorization' jest rozwiązaniem. –

0

po prostu spędzić cały ranek na ten temat [w stosunku szczerze jestem nowy OOC] W każdym razie problem ..

didUpdateLocation kompiluje i nigdy nie jest wywoływana didUpdateLocations kompiluje i działa !!

Nie odpowiedź w tym przypadku wydaje się, ale jest to pytanie, łatwe do popełnienia błędu. Korzystanie z IOS 8.1.3 & Xcode 6.1.1

0

Po prostu dodaj trzy właściwości w Info.plist.

Aby uzyskać bieżącą lokalizację, jeśli nie jest wywołanie metody didUpdateToLocation

NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription privacy - location usage description typu String.

Powiązane problemy