Core Location not working in iOS 8
Solution 1
There is currently a bug in iOS8 beta5 which always deactivate geolocation service for your app (at least for mine).
Go in settings > Privacy > Location services > Your app > Always
.
But I don't know why, but even if you set it to Always
this setting will auto-deactivate, so please be patient and often return in the settings to configure again your app location.
Solution 2
Try declare CLLocationManager *locationManager
in your header file then it works. Unless I have declare it as a global variable it does not ask for permission and update location.
.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
.m
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:(id)self];
[locationManager requestWhenInUseAuthorization];
[locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
}
Delegate methods
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"Getting Location");
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"%@", error.localizedDescription);
}
info.plis
Solution 3
into .plist file add
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
if(IS_OS_8_OR_LATER)
{
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
}
[locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations lastObject];
}
Solution 4
All the steps look complete but run :startUpdatingLocation only after you check for :didChangeAuthorizationStatus.
At this point, please make sure that the authorizationStatus is not kCLAuthorizationStatusNotDetermined or kCLAuthorizationStatusDenied.
If it is either, check for the string entries in info.plist.
If you feel all of it is correct, Make sure that you uninstall the app from the device. Perform a clean build and then run the app on the device.
Solution 5
I had a similar problem migrating my app to iOS 8. As the original code as based on sample code provided by Apple https://developer.apple.com/library/ios/samplecode/GeocoderDemo/Introduction/Intro.html I checked if it had been updated and it had. The main difference is in this function the bit relevant to iOS 8, has been commented. This worked for me.
- (void)startUpdatingCurrentLocation
{
// if location services are restricted do nothing
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted )
{
return;
}
// if locationManager does not currently exist, create it
if (self.locationManager == nil)
{
_locationManager = [[CLLocationManager alloc] init];
[self.locationManager setDelegate:self];
self.locationManager.distanceFilter = 10.0f; // we don't need to be any more accurate than 10m
}
// 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 ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[_locationManager requestWhenInUseAuthorization];
}
[_locationManager startUpdatingLocation];
[self showCurrentLocationSpinner:YES];
}
charleyh
Updated on June 25, 2022Comments
-
charleyh about 2 years
I'm trying to use significant change location monitoring in iOS 8, but the didUpdateLocations method is never called. Here is the code for setting up the location manager:
- (void)viewDidLoad { [super viewDidLoad]; CLLocationManager *locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; [locationManager requestWhenInUseAuthorization]; [locationManager startMonitoringSignificantLocationChanges]; }
Despite calling
requestWhenInUseAuthorization
, nothing pops up to ask the user to authorize it. I have set NSLocationWhenInUseUsageDescription, and it still does not work.didChangeAuthorizationStatus
anddidFailWithError
are also never called. EDIT: I was able to get it to ask the user to allow location services, but even if you click allow it never shows the location. -
charleyh almost 10 yearsThat still isn't working for me. The window pops up and I click allow, but it never actually gives the location.
-
modus almost 10 yearsIs it simulator or device? if it is simulator may be location is not selected in menu / Debug / Location and wifi should be turned on
-
charleyh almost 10 yearsIt is on the simulator, but I've set a location in the debug menu.
-
Andy almost 10 yearsThis is a bug - even the Maps App on the simulator won't show my location.
-
modus almost 10 yearsSimulator is not capable to find your location. The code above working fine for me with Xcode 6 beta 4.
-
Andy almost 10 yearsRetested in beta4 and the problem is fixed.
-
Iqbal Khan almost 10 yearsi found that apps from app store is working fine but adhocs are not.
-
chuckSaldana almost 10 yearsThanks for this, after updating the NSLocationAlwaysUsageDescription key, my code started getting location updates again!
-
Martin almost 10 yearsYou're welcome, but I don't understand how you can still encounter this bug since the final ios8 version is available.
-
Terry Bu over 9 yearsyup, "reset content and settings" in the emulator and rebuilding/running the app solved the problem
-
gsach over 9 years@Developer Are you sure that the reason for the different behaviour is the ad-hoc vs app-store? I think that the difference is between compiling with XCode 5 and XCode 6
-
Iqbal Khan over 9 years@GeorgeSachpatzidis i found the issue was that i am not asking for requestWhenInUseAuthorization. which they had made compulsory in iOS 8
-
iOS Test over 9 yearsI found more CLLocation iOS 8 related issues fixes datacalculation.blogspot.in/2014/11/…