How to trigger action when the button of location permission alert is pressed? I want to perform segue after allow or cancel button is pressed.
I have taken help from this answer and Apple's Developer guide . You can achieve it by setting observor over applicationDidBecomeActive method of Appdelegate using NotificationCenter . Below is the code to achieve your task .
Put the following code in the viewDidLoad of your ViewController .
NotificationCenter.default.addObserver(self,selector: #selector(doSomeThing), name: .UIApplicationDidBecomeActive, object: nil)
Then when ever didBecomeActive is called from Appdelegate this function will be called ... So you can put the action you want to perform in this function
func doSomeThing(){
}
Also put the following code in the the viewDidDisappear of the same ViewController to remove the observer otherwise your app will crash
NotificationCenter.default.removeObserver(self,name: .UIApplicationDidBecomeActive,object: nil)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.