Anonymous Anonymous - 4 years ago 120
Swift Question

How to run a function in Swift when the iPhone or iPad sleeps?

I'm working on an app where you log down what you eat. I have my app set to save the information to my MySQL server every time I close the view (like go back a step in the Navbar) or press the home button. How can I run my saving function down when you turn off the phone.

Answer Source

run the function in applicationDidEnterBackground or applicationWillResignActive in your AppDelegate depending on which one you require. applicationWillResignActive if you want to save even if the app is interrupted by for example a phone call

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download