Time when the application is terminated

57 views Asked by At

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?

1

There are 1 answers

0
Jaydip Finava On BEST ANSWER

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")
}