2019-08-23
Syntax error in LocationManager requestWhenInUseAuthorization
stackoverflow
Question

Error screenshot:

Code:

 if (_locationManager == nil) {
        _locationManager = [[CLLocationManager alloc] init];
        _locationManager.delegate = self;

        _locationManager.requestWhenInUseAuthorization; // this is OK with warning
        _locationManager.requestWhenInUseAuthorization(); // this is giving me error
    }

I am fairly new to iOS development, so not sure how to solve it.

Answer
1

In Objective-C, I think what you want is to properly send the requestWhenInUseAuthorization message to your _locationManager instance, like so:

[_locationManager requestWhenInUseAuthorization];

And as MacUserT mentioned it appears you're blending both Swift and Objective-C style code. I'm not certain how your original snippet compiled, though. Homework for me, perhaps.

Syntax error in LocationManager requestWhenInUseAuthorization
See more ...