Boris Kuzevanov
Boris Kuzevanov

Reputation: 1302

iOS 8 - an issue with GPS location

I've simple class with GPS. also i've serched and i have found no solutions for me.

This example doesn't work for me

So my here it is my code:

@interface MFPointViewController () <CLLocationManagerDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation MFPointViewController{

    CLLocationManager *manager;
    CLGeocoder *geocoder;
    CLPlacemark *placemark;

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.helper = [[AppHelper alloc]init];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    manager = [[CLLocationManager alloc ]init];

    geocoder = [[CLGeocoder alloc]init];

    manager.delegate = self;
    manager.desiredAccuracy = kCLLocationAccuracyBest;

    [manager startUpdatingLocation];
    [self.helper setBackgroundToVIew:self.view];


}

#pragma  mark CLLocationManagerDelegate Methods

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    [self.helper alert:@"Attenzione" message:@"Turn on geolocation" delegate:self];


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

    if(currentLocation != nil){
        NSString *Glat;
        NSString *Glong;

        Glat  = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.latitude];
        Glong = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.longitude];
        // Here goes my logics      

    }
}

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

If i use one device with iOS 7 - this code work's fine.

On iOS 8 no. What can it be?

Thanks to all!

Upvotes: 1

Views: 657

Answers (2)

Paul Cezanne
Paul Cezanne

Reputation: 8741

In addition to nerowolfe's code you also need to add at least one of these to your Info.plist

  • NSLocationWhenInUseUsageDescription
  • NSLocationAlwaysUsageDescription

Put a descriptive string in them telling the user why you want to access their GPS.

Upvotes: 4

nerowolfe
nerowolfe

Reputation: 4817

Add this before startUpdateLocation

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

Upvotes: 2

Related Questions