1

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
T.Jurko
  • 152
  • 11
  • 1
    After the dialog is dismissed your app will resume active, so you can observe the did become active NSNotification – Paulw11 Jan 11 '17 at 12:10
  • 1
    Thank you! http://stackoverflow.com/questions/3639859/handling-applicationdidbecomeactive-how-can-a-view-controller-respond-to-the Here is solution for your answer. – T.Jurko Jan 11 '17 at 15:20

1 Answers1

11

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)
Community
  • 1
  • 1
osama
  • 1,286
  • 18
  • 22