Alert view disappears on its own when calling [locationManager requestWhenInUseAuthorization];

You’re probably being ARC’d. Make sure that you still have a reference to your CLLocationManager. You can easily do this by making it a property. ARC stands for Automatic Reference Counting. In an ARC-enabled project (and unless you are working on something really old or you turned it off on purpose, your project is an … Read more

AuthorizationStatus for CLLocationManager is deprecated on iOS 14

It is now a property of CLLocationManager, authorizationStatus. So, create a CLLocationManager instance: let manager = CLLocationManager() Then you can access the property from there: switch manager.authorizationStatus { case .restricted, .denied: … default: … } There are a few location related changes in iOS 14. See WWDC 2020 What’s new in location. Needless to say, … Read more

How to get Current Location using SwiftUI, without ViewControllers?

You could create a StateObject of your LocationManager by implementing the ObservableObject protocol. With the @Published attribute you can create a publisher object which notify the observers (your view, in this case) when something changes inside that object. That’s why in my LocationManager I added the @Published attribute to those var: locationStatus: CLAuthorizationStatus? it contains … Read more

Battery drain when using CoreLocation Significant Location Monitoring & CoreBluetooth

At the end of the day, Apple’s suggestion of removing location from UIBackgroundModes fixed our battery drain issue. In order to still get locations in the background we had to wrap the [locationManager startLocationUpdates] & [locationManager stopLocationUpdates] calls with: [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler]; [[UIApplication sharedApplication] endBackgroundTask:];

kCLErrorDomain error 2 after geocoding repeatedly with CLGeocoder

I believe the reason is the following: Apple’s geocoder does not answer every request in the same way. Instead, the first requests from a certain device are answered quickly, but if the device has sent say 100 requests or more, the answers arrive slower and slower or requests are not answered at all, which might … Read more

Calculating bearing between two CLLocationCoordinate2Ds

Here the code modified with the changes suggested by Oren Trutner and from myself: #define degreesToRadians(x) (M_PI * x / 180.0) #define radiansToDegrees(x) (x * 180.0 / M_PI) – (float)getHeadingForDirectionFromCoordinate:(CLLocationCoordinate2D)fromLoc toCoordinate:(CLLocationCoordinate2D)toLoc { float fLat = degreesToRadians(fromLoc.latitude); float fLng = degreesToRadians(fromLoc.longitude); float tLat = degreesToRadians(toLoc.latitude); float tLng = degreesToRadians(toLoc.longitude); float degree = radiansToDegrees(atan2(sin(tLng-fLng)*cos(tLat), cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(tLng-fLng))); if (degree … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)