Search code examples
iosswiftxcode8ios10swift2

How to display UIAlertView after some time?


I'm trying to display a UIAlertView after some time (like 5 minutes after doing something in the app). I'm already notifying the user if the app is closed or in a background. But I want to display a UIAlertView while the app is running. I don't want to refresh again and again. After three minutes I have to show some alert like do you want to save or not?


Solution

  • It's working for me :

    self.timer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: #selector(SONGS.displayAlert), userInfo: nil, repeats: false)
    func displayAlert()
    {
       self.message.dismissWithClickedButtonIndex(0,animated: true)
    }