title: How to run a function in Swift when the iPhone or iPad sleeps?
body: <p>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.</p>