Location Manager init called over 100 times on launch

Hi everyone. I am facing a very weird issue where the Location Manager's init method is being called over 100 times on app launch. I have added a print statement to the class init() and when I filter the results from the log I get a staggering 117 entries just in the first few seconds.

Here is my setup:

class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {

    private let locationManager: CLLocationManager
    @Published var locationStatus: CLAuthorizationStatus?
    @Published var lastLocation: CLLocation?


    override init() {
        //initial setup for location monitoring
        locationManager = CLLocationManager()
        locationManager.requestAlwaysAuthorization()

       
        super.init()
        locationManager.delegate = self
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.activityType = .other
        locationManager.pausesLocationUpdatesAutomatically = false
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.showsBackgroundLocationIndicator = false
locationManager.startMonitoringSignificantLocationChanges()

        startMonitoringHomeGeofence()

        let monitoredRegions = locationManager.monitoredRegions

        print("Monitored Regions: \(monitoredRegions.description)")

        print(" | Location Monitoring setup complete(This is the line that is printed out so often)")

    }
}

And in my apps main view I initialize the object with:

@StateObject var locationManager = LocationManager()

I am not sure if this is a real problem, but as this method also initializes the region monitoring which to my knowledge should only be called once on startup and the fact that I get a burst of location updates on my server every time the app launches makes this behavior look like a error in my code, or a bug on apples side.

Has anyone got some ideas for me?

Take care David

I suspect the issue was at the call site? Hope you've solved the mystery since!

My first instinct is also to maybe try a Singleton? static let shared: LocationManager = LocationManager()

Location Manager init called over 100 times on launch
 
 
Q