'AuthorizationStatus for CLLocationManager is deprecated on iOS 14
I use this code to check if I have access to the user location or not
if CLLocationManager.locationServicesEnabled() {
switch CLLocationManager.authorizationStatus() {
case .restricted, .denied:
hasPermission = false
default:
hasPermission = true
}
} else {
print("Location services are not enabled")
}
}
And Xcode(12) yells at me with this warning:
'authorizationStatus()' was deprecated in iOS 14.0
So what is the replacement?
Solution 1:[1]
Objective C Version:
In Class Interface
@property (nonatomic, strong) CLLocationManager *locationManager;
In Class Code
- (id) init {
self = [super init];
if (self != nil) {
self.locationManager = [[CLLocationManager alloc]init];
}
return self;
}
-(CLLocation*)getLocation
{
CLAuthorizationStatus status = [self.locationManager authorizationStatus];
if (status == kCLAuthorizationStatusNotDetermined)
{
[self promptToEnableLocationServices];
return nil;
}
etc...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KeithTheBiped |
