0

I want to know the current time when the app is being terminated. Using this time, I want to do some calculation and store. How can I do this?

Suhas G
  • 45
  • 5

1 Answers1

0

In Your AppDelegate.swift store time in user default in the following method and use them later

func applicationWillTerminate(_ application: UIApplication) {
    let date = Date()
    let df = DateFormatter()
    df.dateFormat = "HH:mm:ss a"
    let stringTime = df.string(from: date) // 11:35:59 AM
    UserDefaults.standard.set(stringTime, forKey: "TerminatedTime")
}