7

Since the new iOS 8 beta release, I have not been able to successfully get a user's location. Prior to the update to iOS 8 I had no issues, but now it always returns 0.000000 as the current latitude and longitude. Is this just a bug in the new release? My code is listed below:

//from the .h file
@interface MasterViewController : PFQueryTableViewController<CLLocationManagerDelegate,UITextFieldDelegate, UISearchBarDelegate, UISearchDisplayDelegate> {

}
@property (nonatomic, strong) CLLocationManager *locationManager;

//from the .m file
@synthesize locationManager = _locationManager;

- (void)viewDidLoad {
  [super viewDidLoad];
  [self.locationManager startUpdatingLocation];
}


- (CLLocationManager *)locationManager {
   if (_locationManager != nil) {
       return _locationManager;
   }

   _locationManager = [[CLLocationManager alloc] init];
   _locationManager.delegate = self;
   _locationManager.desiredAccuracy = kCLLocationAccuracyBest;

   return _locationManager;
}

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

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

UPDATE This question has been answered (Location Services not working in iOS 8). For anyone still struggling with this, to maintain backwards compatibility with iOS 7, I used the code below:

if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])    { } 
Community
  • 1
  • 1
JKo
  • 1,260
  • 1
  • 10
  • 18
  • 3
    I fixed the issue,the answer can be found here: http://stackoverflow.com/questions/24062509/ios-8-location-services-not-working – JKo Jun 11 '14 at 11:06
  • I found the solution here http://datacalculation.blogspot.in/2014/11/how-to-fix-cllocationmanager-location.html – iOS Test Nov 05 '14 at 07:39

1 Answers1

2

As mentioned in your update/comment, iOS8 requires you to use requestAlwaysAuthorization or requestWhenInUseAuthorization as well as a new NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist

But there is something else which is wrong in your code:

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

It has been deprecated in iOS6 and you should now use this new delegate method instead:

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

You can then get the latest location with something like this:

CLLocation *newLocation = [locations lastObject];
Erwan
  • 3,733
  • 30
  • 25
  • I got solution from here http://datacalculation.blogspot.in/2014/11/how-to-fix-cllocationmanager-location.html – iOS Test Nov 05 '14 at 07:40