iOS 6 and Location Services not working

后端 未结 8 2104
走了就别回头了
走了就别回头了 2020-12-09 13:29

I\'ve updated my iOS SDK to version 6. After that I\'ve compiled my app (works fine in iOS 4 & iOS 5) but now the location services doesn\'t wo

8条回答
  •  我在风中等你
    2020-12-09 14:12

    In my case, I had the location manager under a different class and I was calling this class from the main controller. This was not working and the didUpdateLocations was not called.

    //
    //  LocationServices.h
    // 
    
    #import 
    #import 
    
    @interface LocationServices : NSObject  {
        CLLocationManager *locationManager;
    
    }
    
    @property (nonatomic, retain) CLLocationManager *locationManager;
    
    - (void)startLocationServices;
    
    @end
    
    
    
    //  LocationServices.m
    #import "LocationServices.h"
    
    @implementation LocationServices 
    @synthesize locationManager, currentLocation;
    
    - (void)startLocationServices {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.pausesLocationUpdatesAutomatically = NO;
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    
        if ([CLLocationManager locationServicesEnabled]) {
            [locationManager startUpdatingLocation];
    
        } else {
            NSLog(@"Location services is not enabled");
        }
    }
    
    ////////////////////////////////////////////////
    - (void)locationManager:(CLLocationManager *)manager
         didUpdateLocations:(NSArray *)locations {
        CLLocation* location = [locations lastObject];
        NSLog(@"Updated: latitude %+.6f, longitude %+.6f\n",
              location.coordinate.latitude,
              location.coordinate.longitude);
    }
    @end
    
    // Main controller
    - (void)viewDidLoad {   
        [super viewDidLoad];
    
    .....
    
    LocationServices *locationSerices = [[LocationServices alloc]init];
    [locationSerices startLocationServices];
    ......
    }
    

    The above code does not work. Why? I do not know ....you can easily lose interest when you spend so much time trying to do a thing that is supposed to be simple. iOS is very complicated and unfriendly programming environment. There are many ways to do one thing, only one works, you cannot mix and match without introducing a problem. You have to do everything by the book or you or you get nothing. Not even a hint that you did something wrong ... frustrating ...

    Instead when I implemented locationManager:(CLLocationManager *)manager didUpdateLocations: in the main controller everything worked fine

提交回复
热议问题