CLLocationManager startUpdatingLocation ruft nicht locationManager auf: didUpdateLocations: oder locationManager: didFailWithError:

Ich versuche, die CLLocationManager Rahmen meiner iOS-Projekt Zugriff auf den Standort des Benutzers, aber wenn ich call

[locationManager startUpdatingLocation]

weder locationManager:didUpdateLocations: oder locationManager:didFailWithError: werden immer genannt.

//myViewController.h
@interface myViewController : UITableViewController <CLLocationManagerDelegate>
@end

//myViewController.m
@implementation myViewController{
    CLLocationManager *locationManager;
}

//edit
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
}
//finish edit

-(void)getLocation
{
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
UIAlertView *errorAlert = [[UIAlertView alloc]
                           initWithTitle:@"Error" 
                                 message:@"Failed to Get Your Location"              
                                delegate:nil 
                       cancelButtonTitle:@"OK" 
                      otherButtonTitles:nil];
[errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *newLocation = locations[[locations count] -1];
    CLLocation *currentLocation = newLocation;
    NSString *longitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
    NSString *latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];

if (currentLocation != nil) {
   NSLog(@"latitude: %@", latitude);
   NSLog(@"longitude: @"%@", longitude);
}else {
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" 
                                                     delegate:nil 
                                            cancelButtonTitle:@"OK" 
                                            otherButtonTitles:nil];
    [errorAlert show];
}

}
@end

Weder delegate-Methode wird aufgerufen, trotz allem, was es sagt in der Dokumentation:

"Diese Methode gibt sofort einen Wert zurück. Der Aufruf dieser Methode veranlasst den location manager zu einer ersten Position fixieren (das kann einige Sekunden dauern) und Benachrichtigen Sie Ihren Delegaten aufrufen locationManager:didUpdateLocations: Methode [...] zusätzlich zu Ihrer Stellvertretung ein Objekt der Umsetzung der locationManager:didUpdateLocations: Methode, sollte es auch umsetzen locationManager:didFailWithError: Methode zum reagieren auf mögliche Fehler."

Nicht wissen, wie man die debug-Ausgabe.

Dank,

JA

InformationsquelleAutor der Frage ja. | 2014-09-18

Schreibe einen Kommentar