Mradul Kumar
Mradul Kumar

Reputation: 357

cllocationmanager not asking for user permission ios8

Here is my code :

    if (!_locationManager)
    {
        _locationManager = [[CLLocationManager alloc] init];
        [_locationManager setDelegate:self];
    }
    [_locationManager startUpdatingLocation];

please help if someone knows.. Thanks

Upvotes: 2

Views: 1490

Answers (2)

Vivek Molkar
Vivek Molkar

Reputation: 3960

You need to add a call to requestWhenInUseAuthorization when using location services for iOS-8.0 and above. Find the sample code below.

locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;

// this check is required for iOS 8+
// selector 'requestWhenInUseAuthorization' is first introduced in iOS 8
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [locationManager requestWhenInUseAuthorization];
}

[locationManager startUpdatingLocation];

For more information see this blog.

Hope this helps.

Upvotes: 2

methodcalls
methodcalls

Reputation: 61

Add [locationManager requestAlwaysAuthorization]; to your code and add the entry NSLocationAlwaysUsageDescription to your .plist with the value being some sort of message that you want to ask the user for their permission.

Upvotes: 2

Related Questions