Sakshi
Sakshi

Reputation: 15

How to detect if Authorisation Status changed when application is opened from Settings

I am showing a pop up when user denies to the location permission. That pop has a button to take the user to the settings. When the user goes to the settings and allows the permission and then comes back to the application; How can I refresh my view?

enter image description here

Upvotes: 0

Views: 1545

Answers (2)

AtulParmar
AtulParmar

Reputation: 4570

Recheck location permission in applicationWillEnterForeground in appDelegate.swift file and send notification to your view controller using notification observer

yourViewcontroller.swift

override func viewDidLoad() {
     super.viewDidLoad()
     NotificationCenter.default.addObserver(self, selector: #selector(updateLocationPermission(notfication:)), name: "updateLocation", object: nil)
}

@objc func updateLocationPermission(notfication: NSNotification) {
     print("location updated")
}

AppDelegate.swift

func applicationWillEnterForeground(_ application: UIApplication) {
        let nc = NotificationCenter.default
        nc.post(name: Notification.Name("updateLocation"), object: nil)        
}

Upvotes: 0

qtngo
qtngo

Reputation: 1679

When you come back to the application, you should check the location permission status to update the change:

In applicationDidBecomeActive in appDelegate.swift, check CLLocationManager.authorizationStatus()

Upvotes: 1

Related Questions