Core Location Not Working in iOS 8

Core Location not working in iOS 8

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.

Location Services not working in iOS 8

I ended up solving my own problem.

Apparently in iOS 8 SDK, requestAlwaysAuthorization (for background location) or requestWhenInUseAuthorization (location only when foreground) call on CLLocationManager is needed before starting location updates.

There also needs to be NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist with a message to be displayed in the prompt. Adding these solved my problem.

Sample Image

For more extensive information, have a look at: Core-Location-Manager-Changes-in-ios-8

CoreLocation not working in ios 8

Thank you guys for your answers. I found solution of problem. I checked the version of system like:

#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

in startLocationUpdates method:

if(IS_OS_8_OR_LATER) {
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
}

Now it's working properly.

Core Location delegate methods not getting called in iOS 8.3 Xcode 6.3.1

Yeah! Got the solution, Here is my whole code & things added to make it working. Special thanks to @MBarton for his great help. Also Thanks to @ Vinh Nguyen for investing his precious time in solving my issue.

Added Core Location Framework under Target-> General-> Linked Frameworks & Libraries

Added in .plist file

NSLocationAlwaysUsageDescription

See Screenshot:

plist screenshot

In my ViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKAnnotation.h>

// #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

@interface ViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
{
__weak IBOutlet UINavigationItem *navigationItem;
}

@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property(nonatomic, retain) CLLocationManager *locationManager;

@end

Then in ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize mapView;

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

[self setUpMap];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void)setUpMap
{
mapView.delegate = self;
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
#ifdef __IPHONE_8_0
// if(IS_OS_8_OR_LATER) {
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
// Use one or the other, not both. Depending on what you put in info.plist
[self.locationManager requestAlwaysAuthorization];
}
#endif
[self.locationManager startUpdatingLocation];

mapView.showsUserLocation = YES;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
}

-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];

self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
NSLog(@"%@", [self deviceLocation]);

//View Area
MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = self.locationManager.location.coordinate.latitude;
region.center.longitude = self.locationManager.location.coordinate.longitude;
region.span.longitudeDelta = 0.005f;
region.span.longitudeDelta = 0.005f;
[mapView setRegion:region animated:YES];

}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
}
- (NSString *)deviceLocation {
return [NSString stringWithFormat:@"latitude: %f longitude: %f", self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude];
}

Ufff...! Got the solution after fighting with many codes since last 5 days...

Core Location doesn't work with Apple watch

Core Location need to be implemented in the ios App and not in the extension (as mentioned in the documentation).
Another thing, in IOS8 you should call requestWhenInUseAuthorization before calling startUpdatingLocation.

// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}

About the GPX file - the simulator seems not to like it. It just doesn't play.

CoreLocation not working in Today Extension

You can do 2 things:

  • Check if it works on a real device.
  • Or simulate the location using a gpx file instead of a predefined location in Xcode build scheme (I checked this myself and it works)

Sample gpx file content:



<gpx version="1.1" creator="Xcode"> 
<wpt lat="47.52789018096815" lon="7.385249894876031"></wpt>
<wpt lat="47.52720984945248" lon="7.382647784661411"></wpt>
</gpx>

Core Location to an iOS Framework

you can add your decription in NSLocationAlwaysUsageDescription & NSLocationWhenInUseUsageDescription in plist

This code put into AppDelegate file

     var locationManager:CLLocationManager?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

//You can give this permission for fetch current location
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound;
var setting = UIUserNotificationSettings(forTypes: type, categories: nil);
UIApplication.sharedApplication().registerUserNotificationSettings(setting);
UIApplication.sharedApplication().registerForRemoteNotifications();

locationManager = CLLocationManager()
locationManager?.requestAlwaysAuthorization()
locationManager?.delegate = self
locationManager?.startUpdatingLocation()

// Override point for customization after application launch.
return true
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if let location = locations.first as? CLLocation {
println(location)
}
}

CLFloor returning nil in iOS 8

based on these 2 links from Apple's website

CLFloor Ref

CLLoaction Class Ref

Discussion
If floor information is not available for the current location, the value of this property is nil.

I'm not expert in swift but i think
returns nil possibly means that there is no floor information at that location.



Related Topics



Leave a reply



Submit