Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 beta - Location Manager Not Registering User Location

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)])    { } 
like image 380
JKo Avatar asked Jun 11 '14 10:06

JKo


1 Answers

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];
like image 61
Erwan Avatar answered Oct 17 '22 01:10

Erwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!