Anonymous
Anonymous

Reputation: 15

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.

Upvotes: 0

Views: 92

Answers (1)

Mentos
Mentos

Reputation: 483

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

Upvotes: 2

Related Questions