Reputation: 15
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?
Upvotes: 0
Views: 1545
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
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