Search code examples
swiftuicore-location

How to reset core location to ASK for permission to request location in swiftUI?


My core location request worked and I was able to authorize location always..

Now I want to test the flow again but the popup doesn't appear anymore.

I cleaned the build, tried with iPhone simulator, etc but nothing works

Is there a way to reset core Location to request location AGAIN so I can test multiple scenarios?

Button(action: {
                    //save username (to create user once we have password and email
                    
                    if localizationModel.authorizationState == .notDetermined {
                        // If undetermined, show onboarding
                        goWhenTrue = false
                    }
                    else if localizationModel.authorizationState == .authorizedAlways ||
                                localizationModel.authorizationState == .authorizedWhenInUse {
                        // If approved, show home view
                        goWhenTrue = true
                    }
                    else {
                        // If denied show denied view
                        self.deniedLocation.toggle()
                    }
                        

Solution

  • Welcome to Stack Overflow! There are two ways to accomplish this. You can go into the simulator and simply switch permissions to "Ask Next Time" under Privacy > Location Services. However, if you want to start from scratch, you can reset the simulator under the Simulator Menu Device > Erase All Contents and Settings….