How to stop iOS app from request location services permission on app open?

728 Views Asked by At

Something in my app broke. The previous behavior--which was working really well until recently--was the following: I use iOS location services, but in onboarding, ONLY when a specific button is pressed should the pop up requesting location permissions appear (this is because .requestWhenInUseAuthorization() is run when the button is pressed). The problem is that for some reason, the pop up requesting location permissions appears when the app runs before the button is even pressed. There's nothing in my didFinishLaunchingWithOptions() function related to location services.

Even when I remove all the .requestWhenInUseAuthorization() function calls from my app, the pop up still appears on app open. This leads me to believe it's some kind of default behavior Apple recently added. Anyone know how to disable it?

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        switch status {
            case .notDetermined:
                if appState.currentScreen == .changeLocationPermissions {
                    primaryManager?.requestWhenInUseAuthorization()
                }
                print("LOCATION PICKER: Not determined")
                authorizationStatus = .notDetermined
                break
            case .authorizedWhenInUse:
                print("LOCATION PICKER: Authorized When In Use")
                authorizationStatus = .authorizedWhenInUse
                primaryManager!.startUpdatingLocation()
                break
            case .authorizedAlways:
                print("LOCATION PICKER: Authorized Always")
                authorizationStatus = .authorizedAlways
                primaryManager!.startUpdatingLocation()
                break
            case .restricted:
                print("LOCATION PICKER: Restricted")
                authorizationStatus = .restricted
                break
            case .denied:
                print("You need to make sure Location Services are enabled.")
                authorizationStatus = .denied
                break
            default:
                break
        }
    }

My info.plist file:

https://i.stack.imgur.com/c6XX1.png

0

There are 0 best solutions below